Class: Vedeu::Groups::DSL
- Inherits:
-
Object
- Object
- Vedeu::Groups::DSL
- Includes:
- DSL
- Defined in:
- lib/vedeu/groups/dsl.rb
Overview
Interfaces can be configured to be part of a named group. Once an interface is a member of group, the group can be affected by other controls. For example, assuming the client application is a simple Git client, it may have a group called ‘commit’. The ‘commit’ group will contain the interfaces ‘diff’ (to show the changes), ‘staged’ (to show which files are staged) and ‘unstaged’. A refresh of the ‘commit’ group would cause all interfaces belonging to the group to refresh. Similarly, showing or hiding the group would of course, show or hide the interfaces of that group.
Instance Attribute Summary collapse
-
#client ⇒ Object
included
from DSL
readonly
protected
The object instance where the DSL is being used.
-
#model ⇒ void
included
from DSL
readonly
protected
The new model object which the DSL is constructing.
Class Method Summary collapse
-
.group(name, &block) ⇒ Vedeu::Groups::Group
Specify a new group of interfaces with a simple DSL.
Instance Method Summary collapse
-
#add(name) ⇒ Vedeu::Groups::Group
Add the named interface to this group.
-
#attributes ⇒ Hash<Symbol => void>
included
from DSL
private
Returns the default attributes for the new model.
-
#initialize(model, client = nil) ⇒ void
included
from DSL
Returns a new instance of the DSL class including DSL.
-
#members(*names) ⇒ Array<String>
Add the named interfaces to this group in bulk.
-
#method_missing(method, *args, &block) ⇒ void
included
from DSL
private
Attempts to find the missing method on the client object.
-
#name ⇒ NilClass|String|Symbol
included
from DSL
Returns the model name if available.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Vedeu::DSL
Instance Attribute Details
#client ⇒ Object (readonly, protected) Originally defined in module DSL
Returns The object instance where the DSL is being used.
#model ⇒ void (readonly, protected) Originally defined in module DSL
This method returns an undefined value.
Returns The new model object which the DSL is constructing.
Class Method Details
.group(name, &block) ⇒ Vedeu::Groups::Group
Specify a new group of interfaces with a simple DSL. Creating a group with the same name as an existing group overwrites the existing group.
The example below resembles ‘vim’ (the popular terminal-based text editor):
Vedeu.group :title_screen do
add :welcome_interface
# ... some code
end
Vedeu.group :main_screen do
add :editor_interface
add :status_interface
add :command_interface
# ... some code
end
or more succinctly:
Vedeu.group :main_screen do
members :editor_interface,
:status_interface,
:command_interface
# ... some code
end
or when defining an interface:
Vedeu.interface :some_interface do
group :some_group
# ... some code
end
61 62 63 64 65 66 |
# File 'lib/vedeu/groups/dsl.rb', line 61 def self.group(name, &block) fail Vedeu::Error::MissingRequired unless name fail Vedeu::Error::RequiresBlock unless block_given? Vedeu::Groups::Group.build(name: name, &block).store end |
Instance Method Details
#add(name) ⇒ Vedeu::Groups::Group
Add the named interface to this group.
Vedeu.group :main_screen do
add :editor_interface
end
76 77 78 |
# File 'lib/vedeu/groups/dsl.rb', line 76 def add(name) model.add(name) end |
#attributes ⇒ Hash<Symbol => void> (private) Originally defined in module DSL
Specific DSL classes may be overriding this method.
Returns the default attributes for the new model.
#initialize(model, client = nil) ⇒ void Originally defined in module DSL
Returns a new instance of the DSL class including Vedeu::DSL.
#members(*names) ⇒ Array<String>
Add the named interfaces to this group in bulk.
Vedeu.group :main_screen do
members [:editor_interface,
:some_interface,
:other_interface]
end
90 91 92 |
# File 'lib/vedeu/groups/dsl.rb', line 90 def members(*names) names.each { |name| add(name) } end |
#name ⇒ NilClass|String|Symbol Originally defined in module DSL
Returns the model name if available.