Class: BackgroundServices::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/background_services/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/background_services/group.rb', line 4

def name
  @name
end

#teamsObject

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

#startObject



10
11
12
13
14
# File 'lib/background_services/group.rb', line 10

def start
  @teams.each do |k, team|
    team.start
  end
end

#stopObject



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