Class: Tantot::Agent::Registry
- Inherits:
-
Object
- Object
- Tantot::Agent::Registry
- Includes:
- Singleton
- Defined in:
- lib/tantot/agent/registry.rb
Instance Method Summary collapse
- #agent(agent_id) ⇒ Object
- #clear ⇒ Object
- #each_agent ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(watch) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
6 7 8 |
# File 'lib/tantot/agent/registry.rb', line 6 def initialize @agents = {} end |
Instance Method Details
#agent(agent_id) ⇒ Object
19 20 21 |
# File 'lib/tantot/agent/registry.rb', line 19 def agent(agent_id) @agents[agent_id.to_s] end |
#clear ⇒ Object
29 30 31 |
# File 'lib/tantot/agent/registry.rb', line 29 def clear @agents.clear end |
#each_agent ⇒ Object
23 24 25 26 27 |
# File 'lib/tantot/agent/registry.rb', line 23 def each_agent @agents.values.each do |agent| yield agent end end |
#register(watch) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/tantot/agent/registry.rb', line 10 def register(watch) agent_class, watch_id = Tantot::Agent.resolve!(watch) agent = @agents.fetch(watch_id.to_s) do agent_class.new(watch_id).tap {|new_agent| @agents[watch_id.to_s] = new_agent} end agent.add_watch(watch) agent end |