Class: Vedeu::Groups::Group
- Inherits:
-
Object
- Object
- Vedeu::Groups::Group
- Includes:
- Repositories::Model, Toggleable
- Defined in:
- lib/vedeu/groups/group.rb,
lib/vedeu/groups/repository.rb
Overview
Groups
Instance Attribute Summary collapse
- #name ⇒ String
- #repository ⇒ Vedeu::Repositories::Repository included from Repositories::Model
-
#visible ⇒ Boolean
(also: #visible?)
included
from Toggleable
Whether the toggleable is visible.
Class Method Summary collapse
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable is nil or empty.
-
#add(member) ⇒ Vedeu::Groups::Group
Add a member to the group by name.
-
#attributes ⇒ Hash<Symbol => void>
Returns the attributes of the group.
-
#by_zindex ⇒ Array<String>
Return the members of the group sorted by the zindex of the members.
-
#defaults ⇒ Hash
private
Returns the default options/attributes for this class.
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
-
#deputy(client = nil) ⇒ void
included
from Repositories::Model
Returns a DSL instance responsible for defining the DSL methods of this model.
-
#dsl_class ⇒ String
included
from Repositories::Model
private
Returns the DSL class name responsible for this model.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#hide ⇒ Vedeu::Groups::Group
Hide the named group of interfaces, or without a name, the group of the currently focussed interface.
-
#initialize(attributes = {}) ⇒ Vedeu::Groups::Group
constructor
Return a new instance of Vedeu::Groups::Group.
-
#interfaces ⇒ Array<Vedeu::Interfaces::Interface]
private
Return the interfaces for all members of the group.
-
#members ⇒ Set
Return the members of the group.
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
-
#remove(member) ⇒ Vedeu::Groups::Group
Remove a member from the group by name.
-
#reset ⇒ Vedeu::Groups::Group
Remove all members from the group.
-
#show ⇒ Vedeu::Groups::Group
Show the named group of interfaces, or without a name, the group of the currently focussed interface.
-
#snake_case(name) ⇒ String
included
from Common
Converts a class name to a lowercase snake case string.
-
#store ⇒ void
included
from Repositories::Model
The model instance stored in the repository.
-
#toggle ⇒ FalseClass|TrueClass
included
from Toggleable
Toggle the visible state and store the model.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Groups::Group
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.
39 40 41 42 43 |
# File 'lib/vedeu/groups/group.rb', line 39 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#name ⇒ String
15 16 17 |
# File 'lib/vedeu/groups/group.rb', line 15 def name @name end |
#repository ⇒ Vedeu::Repositories::Repository Originally defined in module Repositories::Model
#visible ⇒ Boolean Also known as: visible? Originally defined in module Toggleable
Returns Whether the toggleable is visible.
Class Method Details
.store(attributes = {}) ⇒ Vedeu::Groups::Group
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
Returns a boolean indicating whether a variable is nil or empty.
#add(member) ⇒ Vedeu::Groups::Group
Add a member to the group by name.
49 50 51 52 53 |
# File 'lib/vedeu/groups/group.rb', line 49 def add(member) attrs = attributes.merge!(members: members.add(member)) Vedeu::Groups::Group.store(attrs) end |
#attributes ⇒ Hash<Symbol => void>
Returns the attributes of the group.
58 59 60 61 62 63 64 65 |
# File 'lib/vedeu/groups/group.rb', line 58 def attributes { name: name, members: members, repository: repository, visible: visible, } end |
#by_zindex ⇒ Array<String>
Return the members of the group sorted by the zindex of the members.
71 72 73 |
# File 'lib/vedeu/groups/group.rb', line 71 def by_zindex interfaces.sort_by(&:zindex).map(&:name) end |
#defaults ⇒ Hash (private)
Returns the default options/attributes for this class.
154 155 156 157 158 159 160 161 |
# File 'lib/vedeu/groups/group.rb', line 154 def defaults { members: Set.new, name: '', repository: Vedeu.groups, visible: true, } end |
#demodulize(klass) ⇒ String Originally defined in module Common
Removes the module part from the expression in the string.
#deputy(client = nil) ⇒ void Originally defined in module Repositories::Model
This method returns an undefined value.
Returns a DSL instance responsible for defining the DSL methods of this model.
#dsl_class ⇒ String (private) Originally defined in module Repositories::Model
Returns the DSL class name responsible for this model.
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
79 80 81 82 |
# File 'lib/vedeu/groups/group.rb', line 79 def eql?(other) self.class == other.class && name == other.name && members == other.members end |
#hide ⇒ Vedeu::Groups::Group
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.
99 100 101 102 103 104 105 |
# File 'lib/vedeu/groups/group.rb', line 99 def hide super @members.each { |member| Vedeu.trigger(:_hide_interface_, member) } self end |
#interfaces ⇒ Array<Vedeu::Interfaces::Interface] (private)
Return the interfaces for all members of the group.
166 167 168 |
# File 'lib/vedeu/groups/group.rb', line 166 def interfaces members.map { |name| Vedeu.interfaces.by_name(name) } end |
#members ⇒ Set
Return the members of the group.
110 111 112 |
# File 'lib/vedeu/groups/group.rb', line 110 def members @_members ||= Set.new(@members) end |
#present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
#remove(member) ⇒ Vedeu::Groups::Group
Remove a member from the group by name.
118 119 120 121 122 |
# File 'lib/vedeu/groups/group.rb', line 118 def remove(member) attrs = attributes.merge!(members: members.delete(member)) Vedeu::Groups::Group.store(attrs) end |
#reset ⇒ Vedeu::Groups::Group
Remove all members from the group.
127 128 129 130 131 |
# File 'lib/vedeu/groups/group.rb', line 127 def reset attrs = defaults.merge!(name: name) Vedeu::Groups::Group.store(attrs) end |
#show ⇒ Vedeu::Groups::Group
Show the named group of interfaces, or without a name, the group of the currently focussed interface.
141 142 143 144 145 146 147 |
# File 'lib/vedeu/groups/group.rb', line 141 def show super @members.each { |member| Vedeu.trigger(:_show_interface_, member) } self end |
#snake_case(name) ⇒ String Originally defined in module Common
Converts a class name to a lowercase snake case string.
#store ⇒ void Originally defined in module Repositories::Model
Perhaps some validation could be added here?
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.
#toggle ⇒ FalseClass|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.