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?
).freeze
- 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
).freeze
Class Method Summary
collapse
-
.included(klass) ⇒ Object
:reek:ManualDispatch I have no need to actually call human_attribute_name, I just need to know if I have to provide my own.
Instance Method Summary
collapse
Class Method Details
.included(klass) ⇒ Object
:reek:ManualDispatch I have no need to actually call human_attribute_name, I just need to know if I have to provide my own.
240
241
242
243
244
245
246
|
# File 'lib/business_flow/dsl.rb', line 240
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)
klass.include(ErrorSupport::InstanceMethods) unless klass.respond_to?(:read_attribute_for_validation)
end
|
Instance Method Details
#call ⇒ Object
251
252
253
254
255
|
# File 'lib/business_flow/dsl.rb', line 251
def call
return if invalid?
klass = self.class
klass.step_executor.new(klass.step_queue, self).call
end
|
#errors ⇒ Object
299
300
301
|
# File 'lib/business_flow/dsl.rb', line 299
def errors
@errors ||= ActiveModel::Errors.new(self)
end
|
#errors? ⇒ Boolean
303
304
305
306
307
|
# File 'lib/business_flow/dsl.rb', line 303
def errors?
@errors && @errors.present?
end
|
#invalid?(context = nil) ⇒ Boolean
315
316
317
|
# File 'lib/business_flow/dsl.rb', line 315
def invalid?(context = nil)
!valid?(context)
end
|
#valid?(_context = nil) ⇒ Boolean
309
310
311
312
313
|
# File 'lib/business_flow/dsl.rb', line 309
def valid?(_context = nil)
@errors.blank?
end
|