Class: Vedeu::Groups::DSL

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vedeu::DSL

Instance Attribute Details

#clientObject (readonly, protected) Originally defined in module DSL

#modelvoid (readonly, protected) Originally defined in module DSL

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


59
60
61
62
63
# File 'lib/vedeu/groups/dsl.rb', line 59

def self.group(name, &block)
  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


73
74
75
# File 'lib/vedeu/groups/dsl.rb', line 73

def add(name)
  model.add(name)
end

#attributesHash<Symbol => void> (private) Originally defined in module DSL

Note:

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 an 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


87
88
89
# File 'lib/vedeu/groups/dsl.rb', line 87

def members(*names)
  names.each { |name| add(name) }
end