Class: Vedeu::DSL::Group

Inherits:
Object
  • Object
show all
Includes:
Vedeu::DSL
Defined in:
lib/vedeu/dsl/group.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 Vedeu::DSL

#client, #model

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Vedeu::DSL

#attributes, #method_missing

Constructor Details

#initialize(model, client = nil) ⇒ Vedeu::DSL::Group

Returns an instance of DSL::Group.



66
67
68
69
# File 'lib/vedeu/dsl/group.rb', line 66

def initialize(model, client = nil)
  @model  = model
  @client = client
end

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::Models::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

Raises:



55
56
57
58
59
# File 'lib/vedeu/dsl/group.rb', line 55

def self.group(name, &block)
  fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?

  Vedeu::Models::Group.build(name: name, &block).store
end

Instance Method Details

#add(interface_name) ⇒ Vedeu::Models::Group

Add the named interface to this group.

Vedeu.group 'main_screen' do
  add 'editor_interface'
end


79
80
81
# File 'lib/vedeu/dsl/group.rb', line 79

def add(interface_name)
  model.add(interface_name)
end

#members(*interface_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


91
92
93
# File 'lib/vedeu/dsl/group.rb', line 91

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