Module: BusinessFlow::DSL::ClassMethods
- Defined in:
- lib/business_flow/dsl.rb
Overview
Contains the DSL for BusinessFlow
Instance Method Summary collapse
- #build(parameter_object) ⇒ Object
- #call(parameter_object) ⇒ Object
- #call!(*args) ⇒ Object
-
#execute(flow) ⇒ Object
:reek:UtilityFunction.
-
#needs(*fields) ⇒ Object
Requires that a field be retrievable from the initialization parameters.
-
#provides(*fields) ⇒ Object
Declares that you will expose a field to the outside world.
- #step(klass, opts = {}) ⇒ Object
- #step_executor(executor_class = nil) ⇒ Object
- #step_queue ⇒ Object
- #uses(field, klass, opts = {}) ⇒ Object
-
#wants(field, default = proc { nil }, opts = {}) ⇒ Object
Allows a field to be retrieved from the initialiaztion parameters.
Instance Method Details
#build(parameter_object) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/business_flow/dsl.rb', line 58 def build(parameter_object) allocate.tap do |flow| catch(:halt_step) do flow.send(:_business_flow_dsl_initialize, ParameterObject.new(parameter_object), needs) end end end |
#call(parameter_object) ⇒ Object
46 47 48 49 50 |
# File 'lib/business_flow/dsl.rb', line 46 def call(parameter_object) output = flow = build(parameter_object) catch(:halt_step) { output = execute(flow) } output end |
#call!(*args) ⇒ Object
67 68 69 70 71 |
# File 'lib/business_flow/dsl.rb', line 67 def call!(*args) flow = call(*args) raise FlowFailedException, flow if flow.errors.any? flow end |
#execute(flow) ⇒ Object
:reek:UtilityFunction
53 54 55 56 |
# File 'lib/business_flow/dsl.rb', line 53 def execute(flow) flow.call flow end |
#needs(*fields) ⇒ Object
Requires that a field be retrievable from the initialization parameters
This will only require that the field is not nil. The field may still be #empty?
13 14 15 16 |
# File 'lib/business_flow/dsl.rb', line 13 def needs(*fields) @needs ||= FieldList.new([], ParameterField, self) @needs.add_fields(fields) end |
#provides(*fields) ⇒ Object
Declares that you will expose a field to the outside world.
26 27 28 29 |
# File 'lib/business_flow/dsl.rb', line 26 def provides(*fields) @provides ||= FieldList.new([], PublicField, self) @provides.add_fields(fields) end |
#step(klass, opts = {}) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/business_flow/dsl.rb', line 37 def step(klass, opts = {}) step = Step.new(Callable.new(klass), opts) step_queue.push(step) step.outputs .values .select { |field| field.is_a?(Symbol) } .each { |field| Field.new(field).add_to(self) } end |
#step_executor(executor_class = nil) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/business_flow/dsl.rb', line 77 def step_executor(executor_class = nil) if executor_class @executor_class = executor_class else @executor_class ||= ::BusinessFlow::DefaultStepExecutor end end |
#step_queue ⇒ Object
73 74 75 |
# File 'lib/business_flow/dsl.rb', line 73 def step_queue @step_queue ||= [] end |
#uses(field, klass, opts = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/business_flow/dsl.rb', line 31 def uses(field, klass, opts = {}) step = Step.new(Callable.new(klass), opts) retriever = proc { step.call(self).output } UsesField.new(field, retriever).add_to(self) end |
#wants(field, default = proc { nil }, opts = {}) ⇒ Object
Allows a field to be retrieved from the initialiaztion parameters
19 20 21 22 23 |
# File 'lib/business_flow/dsl.rb', line 19 def wants(field, default = proc { nil }, opts = {}) internal_name = "wants_#{field}".to_sym uses(internal_name, default, opts) ParameterField.new(field, internal_name).add_to(self) end |