Class: WorkflowTemplate::Action::Validated::Prepared

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Abstract::Prepared
Defined in:
lib/workflow_template/action/validated.rb

Direct Known Subclasses

Simple::Prepared, Wrapper::Prepared

Constant Summary collapse

FATAL_SUBCLASSES =
Fatal.constants.map { |name| Fatal.const_get(name) }.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Abstract

#describe

Constructor Details

#initialize(unprepared, validations) ⇒ Prepared

Returns a new instance of Prepared.



57
58
59
60
61
# File 'lib/workflow_template/action/validated.rb', line 57

def initialize(unprepared, validations)
  @unprepared = unprepared
  @validations = validations
  freeze
end

Instance Attribute Details

#unpreparedObject (readonly)

Returns the value of attribute unprepared.



69
70
71
# File 'lib/workflow_template/action/validated.rb', line 69

def unprepared
  @unprepared
end

#validationsObject (readonly)

Returns the value of attribute validations.



69
70
71
# File 'lib/workflow_template/action/validated.rb', line 69

def validations
  @validations
end

Class Method Details

.instance(unprepared, validations) ⇒ Object



53
54
55
# File 'lib/workflow_template/action/validated.rb', line 53

def self.instance(unprepared, validations)
  new unprepared, validations.resolve_validations(unprepared.validates)
end

Instance Method Details

#perform(state, receiver, &block) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/workflow_template/action/validated.rb', line 71

def perform(state, receiver, &block)
  invoke_validated(state, receiver, &block)
rescue *FATAL_SUBCLASSES
  raise
rescue Fatal => e
  detailed = Fatal::Detailed.new(name, state.bare_state, e.message)
  raise detailed
rescue ArgumentError => e
  invocation = method(:invoke_validated)
  raise Fatal::ArgumentError.new(name, e.message) if Fatal::ArgumentError.depth(e, invocation) == 2

  handle_standard_error(e, state)
rescue StandardError => e
  handle_standard_error(e, state)
end

#prepare(validations) ⇒ Object



65
66
67
# File 'lib/workflow_template/action/validated.rb', line 65

def prepare(validations)
  self.class.instance(unprepared, validations)
end