Class: AgentC::Processor
- Inherits:
-
Object
- Object
- AgentC::Processor
- Defined in:
- lib/agent_c/processor.rb
Defined Under Namespace
Classes: Handler
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
Instance Method Summary collapse
- #abort! ⇒ Object
- #abort? ⇒ Boolean
- #add_task(record, handler) ⇒ Object
- #call ⇒ Object
-
#initialize(context:, handlers:) ⇒ Processor
constructor
A new instance of Processor.
Constructor Details
#initialize(context:, handlers:) ⇒ Processor
Returns a new instance of Processor.
15 16 17 18 |
# File 'lib/agent_c/processor.rb', line 15 def initialize(context:, handlers:) @context = context @handlers = handlers.transform_keys(&:to_s) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
14 15 16 |
# File 'lib/agent_c/processor.rb', line 14 def context @context end |
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
14 15 16 |
# File 'lib/agent_c/processor.rb', line 14 def handlers @handlers end |
Instance Method Details
#abort! ⇒ Object
36 37 38 |
# File 'lib/agent_c/processor.rb', line 36 def abort! @abort = true end |
#abort? ⇒ Boolean
40 41 42 |
# File 'lib/agent_c/processor.rb', line 40 def abort? @abort end |
#add_task(record, handler) ⇒ Object
20 21 22 23 24 |
# File 'lib/agent_c/processor.rb', line 20 def add_task(record, handler) raise ArgumentError.new("invalid handler") unless handlers.include?(handler.to_s) store.task.find_or_create_by!(record:, handler:) end |
#call ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/agent_c/processor.rb', line 26 def call(&) raise "must provide at least one workspace" if workspace_count == 0 if workspace_count == 1 call_synchronous(context.workspaces.first, &) else call_asynchronous(&) end end |