module BusinessFlow::DSL
Core DSL
for BusinessFlow
. The relevant methods are all in ClassMethods
.
Constants
- FROM_FLOW_PREAMBLE
- RESULT_DEF
Attributes
parameter_object[R]
Public Class Methods
included(klass)
click to toggle source
:reek: ManualDispatch I have no need to actually call human_attribute_name, I just need to know if I have to provide my own.
# File lib/business_flow/dsl.rb, line 227 def self.included(klass) klass.extend(ClassMethods) klass.class_eval RESULT_DEF, __FILE__, __LINE__ klass.extend(ErrorSupport) unless klass.respond_to?(:human_attribute_name) end
Public Instance Methods
call()
click to toggle source
# File lib/business_flow/dsl.rb, line 236 def call return if invalid? klass = self.class klass.step_executor.new(klass.step_queue, self).call end
errors()
click to toggle source
# File lib/business_flow/dsl.rb, line 284 def errors @errors ||= ActiveModel::Errors.new(self) end
errors?()
click to toggle source
# File lib/business_flow/dsl.rb, line 288 def errors? # We're explicitly using the instance variable here so that if no # errors have been created, we don't initialize the error object. @errors && @errors.present? end
invalid?(context = nil)
click to toggle source
# File lib/business_flow/dsl.rb, line 300 def invalid?(context = nil) !valid?(context) end
valid?(_context = nil)
click to toggle source
# File lib/business_flow/dsl.rb, line 294 def valid?(_context = nil) # We're explicitly using the instance variable here so that if no # errors have been created, we don't initialize the error object. @errors.blank? end
Private Instance Methods
_business_flow_dsl_initialize(parameter_object, needs)
click to toggle source
Responsible for setting the parameter object and validating inputs. This is a method directly on the object instead of something we handle through instance_eval/exec for performance reasons. :reek: NilCheck This is where we ensure that our needs are non-nil.
# File lib/business_flow/dsl.rb, line 246 def _business_flow_dsl_initialize(parameter_object, needs) @parameter_object = parameter_object needs.each do |need| if send(need).nil? errors[need] << 'must not be nil' throw :halt_step end end initialize end
_business_flow_dsl_parameters()
click to toggle source
# File lib/business_flow/dsl.rb, line 276 def _business_flow_dsl_parameters @_business_flow_dsl_parameters ||= Hash[ self.class.inputs.all.map do |input| [input, _business_flow_parameter_inner_fetch(input)] end ] end
_business_flow_parameter_fetch(key) { || ... }
click to toggle source
:reek: NilCheck
# File lib/business_flow/dsl.rb, line 258 def _business_flow_parameter_fetch(key) value = _business_flow_parameter_inner_fetch(key) # We only want to fall back to a default if we were # given nil. Other falsy vlues should be directly used. return yield if value.nil? && block_given? value end
_business_flow_parameter_inner_fetch(key)
click to toggle source
# File lib/business_flow/dsl.rb, line 266 def _business_flow_parameter_inner_fetch(key) if @parameter_object.is_a?(Hash) && @parameter_object.key?(key) @parameter_object[key] else @parameter_object.public_send(key) end rescue NoMethodError nil end