Class: BackgroundServices::Group
- Inherits:
-
Object
- Object
- BackgroundServices::Group
- Defined in:
- lib/background_services/group.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#teams ⇒ Object
Returns the value of attribute teams.
Instance Method Summary collapse
-
#initialize(name) ⇒ Group
constructor
A new instance of Group.
- #register_team(team) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #union(other) ⇒ Object
- #unregister_team(team) ⇒ Object
Constructor Details
#initialize(name) ⇒ Group
Returns a new instance of Group.
6 7 8 |
# File 'lib/background_services/group.rb', line 6 def initialize(name) @name, @teams = name, {} end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/background_services/group.rb', line 4 def name @name end |
#teams ⇒ Object
Returns the value of attribute teams.
4 5 6 |
# File 'lib/background_services/group.rb', line 4 def teams @teams end |
Instance Method Details
#register_team(team) ⇒ Object
22 23 24 |
# File 'lib/background_services/group.rb', line 22 def register_team(team) @teams[team.team_id] = team end |
#start ⇒ Object
10 11 12 13 14 |
# File 'lib/background_services/group.rb', line 10 def start @teams.each do |k, team| team.start end end |
#stop ⇒ Object
16 17 18 19 20 |
# File 'lib/background_services/group.rb', line 16 def stop @teams.each do |k, team| team.stop end end |
#union(other) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/background_services/group.rb', line 30 def union(other) group = Group.new("#{@name}_and_#{other.name}") ids = @teams.keys & other.teams.keys group.teams = ids.inject({}) do |m, id| m[id] = @teams[id] || other.teams[id] m end group end |
#unregister_team(team) ⇒ Object
26 27 28 |
# File 'lib/background_services/group.rb', line 26 def unregister_team(team) @teams.delete(team.team_id) end |