Class: SpotFlow::Context
- Inherits:
-
Object
- Object
- SpotFlow::Context
- Defined in:
- lib/spot_flow/context.rb
Instance Attribute Summary collapse
-
#bpmn_definitions ⇒ Object
readonly
Returns the value of attribute bpmn_definitions.
-
#decisions ⇒ Object
readonly
Returns the value of attribute decisions.
-
#dmn_definitions ⇒ Object
readonly
Returns the value of attribute dmn_definitions.
-
#executions ⇒ Object
readonly
Returns the value of attribute executions.
-
#processes ⇒ Object
readonly
Returns the value of attribute processes.
-
#services ⇒ Object
readonly
Returns the value of attribute services.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Instance Method Summary collapse
- #decision_by_id(id) ⇒ Object
- #default_process ⇒ Object
- #dmn_definitions_by_decision_id(decision_id) ⇒ Object
- #element_by_id(id) ⇒ Object
- #execution_by_id(id) ⇒ Object
- #execution_by_step_id(step_id) ⇒ Object
-
#initialize(sources = [], processes: [], decisions: [], services: {}) ⇒ Context
constructor
A new instance of Context.
- #inspect ⇒ Object
- #notify_listener(*args) ⇒ Object
- #process_by_id(id) ⇒ Object
- #restore(execution_state) ⇒ Object
- #start(process_id: nil, start_event_id: nil, variables: {}) ⇒ Object
- #start_with_message(message_name:, variables: {}) ⇒ Object
Constructor Details
#initialize(sources = [], processes: [], decisions: [], services: {}) ⇒ Context
Returns a new instance of Context.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/spot_flow/context.rb', line 8 def initialize(sources = [], processes:[], decisions:[], services: {}) @sources = Array.wrap(sources) @processes = Array.wrap(processes) @bpmn_definitions = [] @dmn_definitions = [] @decisions = Array.wrap(decisions) @services = HashWithIndifferentAccess.new((SpotFlow.config.services || {}).merge(services)) @sources.each do |source| if source.include?("http://www.omg.org/spec/DMN/20180521/DC/") definitions = SpotFeel.definitions_from_xml(source) @dmn_definitions << definitions @decisions += definitions.decisions else @processes += SpotFlow.processes_from_xml(source) end end @executions = [] end |
Instance Attribute Details
#bpmn_definitions ⇒ Object (readonly)
Returns the value of attribute bpmn_definitions.
6 7 8 |
# File 'lib/spot_flow/context.rb', line 6 def bpmn_definitions @bpmn_definitions end |
#decisions ⇒ Object (readonly)
Returns the value of attribute decisions.
5 6 7 |
# File 'lib/spot_flow/context.rb', line 5 def decisions @decisions end |
#dmn_definitions ⇒ Object (readonly)
Returns the value of attribute dmn_definitions.
6 7 8 |
# File 'lib/spot_flow/context.rb', line 6 def dmn_definitions @dmn_definitions end |
#executions ⇒ Object (readonly)
Returns the value of attribute executions.
5 6 7 |
# File 'lib/spot_flow/context.rb', line 5 def executions @executions end |
#processes ⇒ Object (readonly)
Returns the value of attribute processes.
5 6 7 |
# File 'lib/spot_flow/context.rb', line 5 def processes @processes end |
#services ⇒ Object (readonly)
Returns the value of attribute services.
5 6 7 |
# File 'lib/spot_flow/context.rb', line 5 def services @services end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
5 6 7 |
# File 'lib/spot_flow/context.rb', line 5 def sources @sources end |
Instance Method Details
#decision_by_id(id) ⇒ Object
92 93 94 |
# File 'lib/spot_flow/context.rb', line 92 def decision_by_id(id) decisions.find { |d| d.id == id } end |
#default_process ⇒ Object
61 62 63 64 |
# File 'lib/spot_flow/context.rb', line 61 def default_process raise "Multiple processes defined, must identify process" if processes.size > 1 processes.first end |
#dmn_definitions_by_decision_id(decision_id) ⇒ Object
96 97 98 |
# File 'lib/spot_flow/context.rb', line 96 def dmn_definitions_by_decision_id(decision_id) dmn_definitions.find { |definitions| definitions.decisions.find { |decision| decision.id == decision_id } } end |
#element_by_id(id) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/spot_flow/context.rb', line 76 def element_by_id(id) processes.each do |process| element = process.element_by_id(id) return element if element end nil end |
#execution_by_id(id) ⇒ Object
84 85 86 |
# File 'lib/spot_flow/context.rb', line 84 def execution_by_id(id) executions.find { |e| e.id == id } end |
#execution_by_step_id(step_id) ⇒ Object
88 89 90 |
# File 'lib/spot_flow/context.rb', line 88 def execution_by_step_id(step_id) executions.find { |e| e.step.id == step_id } end |
#inspect ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/spot_flow/context.rb', line 100 def inspect parts = ["#<Context"] parts << "@processes=#{processes.inspect}" if processes.present? parts << "@decisions=#{decisions.inspect}" if decisions.present? parts << "@executions=#{executions.inspect}" if executions.present? parts.join(" ") + ">" end |
#notify_listener(*args) ⇒ Object
57 58 59 |
# File 'lib/spot_flow/context.rb', line 57 def notify_listener(*args) SpotFlow.config.listener&.call(args) end |
#process_by_id(id) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/spot_flow/context.rb', line 66 def process_by_id(id) processes.each do |process| return process if process.id == id process.sub_processes.each do |sub_process| return sub_process if sub_process.id == id end end nil end |
#restore(execution_state) ⇒ Object
51 52 53 54 55 |
# File 'lib/spot_flow/context.rb', line 51 def restore(execution_state) Execution.deserialize(execution_state, context: self).tap do |execution| executions << execution end end |
#start(process_id: nil, start_event_id: nil, variables: {}) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/spot_flow/context.rb', line 29 def start(process_id: nil, start_event_id: nil, variables: {}) process = process_id ? process_by_id(process_id) : default_process raise ExecutionError.new(process_id ? "Process #{process_id} not found." : "No default process found.") if process.blank? execution = Execution.start(context: self, process: process, start_event_id: start_event_id, variables: variables) executions << execution execution end |
#start_with_message(message_name:, variables: {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/spot_flow/context.rb', line 37 def (message_name:, variables: {}) [].tap do |executions| processes.map do |process| process.start_events.map do |start_event| start_event..map do || if == . Execution.start(context: self, process: process, variables: variables, start_event_id: start_event.id).tap { |execution| executions.push execution } end end end end end end |