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.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
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.
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
#by_zindex ⇒ Array<String>
Return the members of the group sorted by the zindex of the members.
-
#defaults ⇒ Hash<Symbol => Boolean|Set|String| Vedeu::Groups::Repository]
private
Returns the default options/attributes for this class.
-
#deputy(client = nil) ⇒ Vedeu::Groups::DSL
Returns a DSL instance responsible for defining the DSL methods of this model.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
#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.
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#members ⇒ Set
Return the members of the group.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#present?(variable) ⇒ Boolean
included
from Common
private
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
(also: #reset)
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(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#store(&block) ⇒ void
included
from Repositories::Model
The model instance stored in the repository.
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#toggle ⇒ Boolean
included
from Toggleable
Toggle the visible state and store the model.
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
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.
36 37 38 39 40 |
# File 'lib/vedeu/groups/group.rb', line 36 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#name ⇒ String
17 18 19 |
# File 'lib/vedeu/groups/group.rb', line 17 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.
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.
#add(member) ⇒ Vedeu::Groups::Group
Add a member to the group by name.
46 47 48 49 50 |
# File 'lib/vedeu/groups/group.rb', line 46 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.
55 56 57 58 59 60 61 62 |
# File 'lib/vedeu/groups/group.rb', line 55 def attributes { name: name, members: members, repository: repository, visible: visible, } end |
#become(klass, attributes) ⇒ Class 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 one class into another.
#boolean(value) ⇒ 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 the value was a boolean.
#boolean?(value) ⇒ 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 the value is a Boolean.
#by_zindex ⇒ Array<String>
Return the members of the group sorted by the zindex of the members.
68 69 70 |
# File 'lib/vedeu/groups/group.rb', line 68 def by_zindex interfaces.sort_by(&:zindex).map(&:name) end |
#defaults ⇒ Hash<Symbol => Boolean|Set|String| Vedeu::Groups::Repository] (private)
Returns the default options/attributes for this class.
165 166 167 168 169 170 171 172 |
# File 'lib/vedeu/groups/group.rb', line 165 def defaults { members: Set.new, name: '', repository: Vedeu.groups, visible: true, } end |
#deputy(client = nil) ⇒ Vedeu::Groups::DSL
Returns a DSL instance responsible for defining the DSL methods of this model.
80 81 82 |
# File 'lib/vedeu/groups/group.rb', line 80 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.
88 89 90 91 |
# File 'lib/vedeu/groups/group.rb', line 88 def eql?(other) self.class == other.class && name == other.name && members == other.members end |
#escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#falsy?(value) ⇒ 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 the value should be considered false.
#hash?(value) ⇒ 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 the value is a Hash.
#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.
108 109 110 111 112 113 114 |
# File 'lib/vedeu/groups/group.rb', line 108 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.
177 178 179 |
# File 'lib/vedeu/groups/group.rb', line 177 def interfaces members.map { |name| Vedeu.interfaces.by_name(name) } end |
#line_model? ⇒ 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 the model is a Views::Line.
#members ⇒ Set
Return the members of the group.
119 120 121 |
# File 'lib/vedeu/groups/group.rb', line 119 def members @_members ||= Set.new(@members) end |
#numeric?(value) ⇒ 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 the value is a Fixnum.
#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.
#remove(member) ⇒ Vedeu::Groups::Group
Remove a member from the group by name.
127 128 129 130 131 |
# File 'lib/vedeu/groups/group.rb', line 127 def remove(member) attrs = attributes.merge!(members: members.delete(member)) Vedeu::Groups::Group.store(attrs) end |
#reset! ⇒ Vedeu::Groups::Group Also known as: reset
Remove all members from the group.
136 137 138 139 140 |
# File 'lib/vedeu/groups/group.rb', line 136 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.
151 152 153 154 155 156 157 |
# File 'lib/vedeu/groups/group.rb', line 151 def show super @members.each { |member| Vedeu.trigger(:_show_interface_, member) } self end |
#snake_case(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.
Converts a class name to a lowercase snake case string.
#store(&block) ⇒ 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.
#stream_model? ⇒ 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 the model is a Views::Stream.
#string?(value) ⇒ 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 the value is a Fixnum.
#toggle ⇒ Boolean 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.
#truthy?(value) ⇒ 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 the value should be considered true.
#view_model? ⇒ 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 the model is a Views::View.