Class: Vedeu::Groups::Group

Inherits:
Object
  • Object
show all
Includes:
Repositories::Model, Toggleable
Defined in:
lib/vedeu/groups/group.rb,
lib/vedeu/groups/repository.rb

Overview

Groups

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Groups::Group

Note:

A group being visible or not may not necessarily mean the members are of the same state.

Return a new instance of Vedeu::Groups::Group.

Parameters:

  • attributes (Hash<Symbol => Boolean|Set|String| Vedeu::Groups::Repository]) (defaults to: {})

    ttributes [Hash<Symbol => Boolean|Set|String| Vedeu::Groups::Repository]

Options Hash (attributes):

  • members (Set)

    A collection of names of interfaces belonging to this group.

  • name (String|Symbol)

    The name of the group.

  • repository (Object)
    Vedeu::Repositories::Repository

    The storage for all Group models.

  • visible (Boolean)

    Whether the group is visible or not.



40
41
42
43
44
# File 'lib/vedeu/groups/group.rb', line 40

def initialize(attributes = {})
  defaults.merge!(attributes).each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#nameString

Returns:

  • (String)


15
16
17
# File 'lib/vedeu/groups/group.rb', line 15

def name
  @name
end

#repositoryVedeu::Repositories::Repository Originally defined in module Repositories::Model

#visibleBoolean Also known as: visible? Originally defined in module Toggleable

Returns Whether the toggleable is visible.

Returns:

  • (Boolean)

    Whether the toggleable is visible.

Class Method Details

.store(attributes = {}) ⇒ Vedeu::Groups::Group

Parameters:

  • attributes (Hash<Symbol => Boolean|Set|String| Vedeu::Groups::Repository]) (defaults to: {})

    ttributes [Hash<Symbol => Boolean|Set|String| Vedeu::Groups::Repository]

Returns:



19
20
21
# File 'lib/vedeu/groups/group.rb', line 19

def self.store(attributes = {})
  new(attributes).store
end

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#add(member) ⇒ Vedeu::Groups::Group

Add a member to the group by name.

Parameters:

  • member (String)

Returns:



50
51
52
53
54
# File 'lib/vedeu/groups/group.rb', line 50

def add(member)
  attrs = attributes.merge!(members: members.add(member))

  Vedeu::Groups::Group.store(attrs)
end

#attributesHash<Symbol => void>

Returns the attributes of the group.

Returns:

  • (Hash<Symbol => void>)


59
60
61
62
63
64
65
66
# File 'lib/vedeu/groups/group.rb', line 59

def attributes
  {
    name:       name,
    members:    members,
    repository: repository,
    visible:    visible,
  }
end

#by_zindexArray<String>

Return the members of the group sorted by the zindex of the members.

Returns:

  • (Array<String>)


72
73
74
# File 'lib/vedeu/groups/group.rb', line 72

def by_zindex
  interfaces.sort_by(&:zindex).map(&:name)
end

#defaultsHash<Symbol => Boolean|Set|String| Vedeu::Groups::Repository] (private)

Returns the default options/attributes for this class.

Returns:

  • (Hash<Symbol => Boolean|Set|String| Vedeu::Groups::Repository])

    Hash<Symbol => Boolean|Set|String| Vedeu::Groups::Repository]



168
169
170
171
172
173
174
175
# File 'lib/vedeu/groups/group.rb', line 168

def defaults
  {
    members:    Set.new,
    name:       '',
    repository: Vedeu.groups,
    visible:    true,
  }
end

#demodulize(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#deputy(client = nil) ⇒ Vedeu::Groups::DSL

Returns a DSL instance responsible for defining the DSL methods of this model.

Parameters:

  • client (Object|NilClass) (defaults to: nil)

    The client binding represents the client application object that is currently invoking a DSL method. It is required so that we can send messages to the client application object should we need to.

Returns:



84
85
86
# File 'lib/vedeu/groups/group.rb', line 84

def deputy(client = nil)
  Vedeu::Groups::DSL.new(self, client)
end

#eql?(other) ⇒ Boolean Also known as: ==

An object is equal when its values are the same.

Parameters:

Returns:

  • (Boolean)


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

def eql?(other)
  self.class == other.class && name == other.name &&
    members == other.members
end

#hideVedeu::Groups::Group

Note:

The action of showing a group will effectively clear the terminal and show the new group, therefore hiding the group may not be necessary.

Hide the named group of interfaces, or without a name, the group of the currently focussed interface. Useful for hiding part of that which is currently displaying in the terminal.

Examples:

Vedeu.trigger(:_hide_group_, name)
Vedeu.hide_group(name)

Returns:



112
113
114
115
116
117
118
# File 'lib/vedeu/groups/group.rb', line 112

def hide
  super

  @members.each { |member| Vedeu.trigger(:_hide_interface_, member) }

  self
end

#interfacesArray<Vedeu::Interfaces::Interface] (private)

Return the interfaces for all members of the group.

Returns:



180
181
182
# File 'lib/vedeu/groups/group.rb', line 180

def interfaces
  members.map { |name| Vedeu.interfaces.by_name(name) }
end

#membersSet

Return the members of the group.

Returns:

  • (Set)


123
124
125
# File 'lib/vedeu/groups/group.rb', line 123

def members
  @_members ||= Set.new(@members)
end

#present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#remove(member) ⇒ Vedeu::Groups::Group

Remove a member from the group by name.

Parameters:

  • member (String)

Returns:



131
132
133
134
135
# File 'lib/vedeu/groups/group.rb', line 131

def remove(member)
  attrs = attributes.merge!(members: members.delete(member))

  Vedeu::Groups::Group.store(attrs)
end

#resetVedeu::Groups::Group

Remove all members from the group.



140
141
142
143
144
# File 'lib/vedeu/groups/group.rb', line 140

def reset
  attrs = defaults.merge!(name: name)

  Vedeu::Groups::Group.store(attrs)
end

#showVedeu::Groups::Group

Show the named group of interfaces, or without a name, the group of the currently focussed interface.

Examples:

Vedeu.trigger(:_show_group_, name)
Vedeu.show_group(name)

Returns:



154
155
156
157
158
159
160
# File 'lib/vedeu/groups/group.rb', line 154

def show
  super

  @members.each { |member| Vedeu.trigger(:_show_interface_, member) }

  self
end

#snake_case(name) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

#storevoid Originally defined in module Repositories::Model

TODO:

Perhaps some validation could be added here?

Note:

If a block is given, store the model, return the model after yielding.

This method returns an undefined value.

Returns The model instance stored in the repository.

#toggleFalseClass|TrueClass Originally defined in module Toggleable

Toggle the visible state and store the model. When the model is hidden, then it is shown, and vice versa.

Returns:

  • (FalseClass|TrueClass)