Class: Expedite::Agents
- Inherits:
-
Object
- Object
- Expedite::Agents
- Defined in:
- lib/expedite/agents.rb
Defined Under Namespace
Classes: Registration
Class Method Summary collapse
- .current ⇒ Object
-
.lookup(agent) ⇒ Object
Retrieves the specified agent.
-
.register(matcher, **named_options) ⇒ Object
Registers a agent.
-
.reset ⇒ Object
Resets registrations to default.
Instance Method Summary collapse
-
#initialize ⇒ Agents
constructor
A new instance of Agents.
- #lookup(agent) ⇒ Object
- #register(matcher, **named_options) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Agents
Returns a new instance of Agents.
80 81 82 |
# File 'lib/expedite/agents.rb', line 80 def initialize @registrations = [] end |
Class Method Details
.current ⇒ Object
46 47 48 |
# File 'lib/expedite/agents.rb', line 46 def self.current @current ||= Agents.new end |
.lookup(agent) ⇒ Object
Retrieves the specified agent
52 53 54 |
# File 'lib/expedite/agents.rb', line 52 def self.lookup(agent) self.current.lookup(agent.to_s) end |
.register(matcher, **named_options) ⇒ Object
Registers a agent. Agents are matched in the order they are registered.
- matcher
-
Wildcard to match a name against.
- named_options
-
Agent options.
Example
Expedite::Agents.register('base' do |name|
puts "Base #{name} started"
end
Expedite::Agents.register('development/abc', parent: 'base') do |name|
puts "Agent #{name} started"
end
70 71 72 |
# File 'lib/expedite/agents.rb', line 70 def self.register(matcher, **) self.current.register(matcher.to_s, **) end |
.reset ⇒ Object
Resets registrations to default
76 77 78 |
# File 'lib/expedite/agents.rb', line 76 def self.reset self.current.reset end |
Instance Method Details
#lookup(agent) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/expedite/agents.rb', line 84 def lookup(agent) ret = @registrations.find do |r| r.match?(agent) end raise AgentNotFoundError, "Agent #{agent.inspect} not found" if ret.nil? ret.agent end |
#register(matcher, **named_options) ⇒ Object
92 93 94 95 96 |
# File 'lib/expedite/agents.rb', line 92 def register(matcher, **) agent = Agent.new(**) @registrations << Registration.new(matcher, agent) agent end |
#reset ⇒ Object
98 99 100 101 |
# File 'lib/expedite/agents.rb', line 98 def reset @registrations = [] nil end |