Module: BusinessFlow::DSL
- Defined in:
- lib/business_flow/dsl.rb
Overview
Core DSL for BusinessFlow. The relevant methods are all in ClassMethods.
Defined Under Namespace
Modules: ClassMethods, ErrorSupport
Classes: Field, FieldList, MemoizedField, ParameterField, PublicField, UsesField
Constant Summary
collapse
- FROM_FLOW_PREAMBLE =
%(
def from_flow(flow)
return if errors?
)
- RESULT_DEF =
%(
class Result
def initialize(errors)
@errors = errors
end
def errors
@errors ||= ActiveModel::Errors.new(self)
end
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
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
def invalid?(context = nil)
!valid?(context)
end
end
)
Class Method Summary
collapse
-
.included(klass) ⇒ Object
:reek:ManualDispatch I have no need to actually call human_attribute_name, :reek:TooManyStatements Breaking this up would add complexity.
Instance Method Summary
collapse
Class Method Details
.included(klass) ⇒ Object
:reek:ManualDispatch I have no need to actually call human_attribute_name, :reek:TooManyStatements Breaking this up would add complexity. I just need to know if I have to provide my own.
253
254
255
256
257
258
259
260
261
|
# File 'lib/business_flow/dsl.rb', line 253
def self.included(klass)
klass.extend(ClassMethods)
klass.class_eval RESULT_DEF, __FILE__, __LINE__
klass.extend(ErrorSupport) unless klass.respond_to?(:human_attribute_name)
klass.extend(ActiveModel::Naming)
return if klass.respond_to?(:read_attribute_for_validation)
klass.include(ErrorSupport::InstanceMethods)
end
|
Instance Method Details
#call ⇒ Object
266
267
268
269
270
271
|
# File 'lib/business_flow/dsl.rb', line 266
def call
return if invalid?
klass = self.class
klass.step_executor.new(klass.step_queue, self).call
end
|
#errors ⇒ Object
313
314
315
|
# File 'lib/business_flow/dsl.rb', line 313
def errors
@errors ||= ActiveModel::Errors.new(self)
end
|
#errors? ⇒ Boolean
317
318
319
320
321
|
# File 'lib/business_flow/dsl.rb', line 317
def errors?
@errors&.present?
end
|
#invalid?(context = nil) ⇒ Boolean
329
330
331
|
# File 'lib/business_flow/dsl.rb', line 329
def invalid?(context = nil)
!valid?(context)
end
|
#valid?(_context = nil) ⇒ Boolean
323
324
325
326
327
|
# File 'lib/business_flow/dsl.rb', line 323
def valid?(_context = nil)
@errors.blank?
end
|