Class: Vedeu::Group
Overview
Interfaces can be associated with one another by being members of the same Group. A Group is a collection of interface names.
Instance Attribute Summary collapse
Attributes included from Model
Instance Method Summary collapse
-
#add(member) ⇒ Group
Add a member to the group by name.
- #defaults ⇒ Hash private
-
#initialize(attributes = {}) ⇒ Group
constructor
Return a new instance of Vedeu::Group.
-
#members ⇒ Set
Return the members as a Set.
-
#remove(member) ⇒ Group
Remove a member from the group by name.
-
#reset ⇒ Group
Remove all members from the group.
Methods included from Model
#demodulize, #deputy, #dsl_class, included, #store
Constructor Details
#initialize(attributes = {}) ⇒ Group
Return a new instance of Vedeu::Group.
22 23 24 25 26 27 28 |
# File 'lib/vedeu/models/group.rb', line 22 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @members = Array(@attributes[:members]) @name = @attributes[:name] @repository = @attributes[:repository] end |
Instance Attribute Details
#name ⇒ String
11 12 13 |
# File 'lib/vedeu/models/group.rb', line 11 def name @name end |
Instance Method Details
#add(member) ⇒ Group
Add a member to the group by name.
34 35 36 37 38 |
# File 'lib/vedeu/models/group.rb', line 34 def add(member) @members = members.add(member) Vedeu::Group.new(name: name, members: @members).store end |
#defaults ⇒ Hash (private)
67 68 69 70 71 72 73 |
# File 'lib/vedeu/models/group.rb', line 67 def defaults { members: [], name: '', repository: Vedeu.groups, } end |
#members ⇒ Set
Return the members as a Set.
43 44 45 |
# File 'lib/vedeu/models/group.rb', line 43 def members @members.to_set end |
#remove(member) ⇒ Group
Remove a member from the group by name.
51 52 53 54 55 |
# File 'lib/vedeu/models/group.rb', line 51 def remove(member) @members = members.delete(member) Vedeu::Group.new(name: name, members: @members).store end |
#reset ⇒ Group
Remove all members from the group.
60 61 62 |
# File 'lib/vedeu/models/group.rb', line 60 def reset Vedeu::Group.new(defaults.merge!(name: name)).store end |