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

Attributes included from DSL

#client, #model

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL

#attributes, #initialize, #method_missing, #name

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vedeu::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

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

  • block (Proc)

Returns:

Raises:



63
64
65
66
67
68
# File 'lib/vedeu/groups/dsl.rb', line 63

def self.group(name, &block)
  raise Vedeu::Error::MissingRequired unless name
  raise 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

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

Returns:



78
79
80
# File 'lib/vedeu/groups/dsl.rb', line 78

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

#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

Parameters:

  • names (Array<String|Symbol>)

Returns:

  • (Array<String>)


92
93
94
# File 'lib/vedeu/groups/dsl.rb', line 92

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