Module: WorkflowTemplate::State::Intermediate

Includes:
Abstract
Defined in:
lib/workflow_template/state/intermediate.rb

Instance Attribute Summary collapse

Attributes included from Abstract

#meta, #wrapped_state

Instance Method Summary collapse

Methods included from Abstract

#bare_state, #error, #error?

Instance Attribute Details

#default_strategyObject (readonly)

Returns the value of attribute default_strategy.



16
17
18
# File 'lib/workflow_template/state/intermediate.rb', line 16

def default_strategy
  @default_strategy
end

Instance Method Details

#apply_validations(validations) ⇒ Object



30
31
32
33
34
35
# File 'lib/workflow_template/state/intermediate.rb', line 30

def apply_validations(validations)
  return self if error?

  wrapped_state = self.class.validate(self.wrapped_state, validations)
  self.class.send :new, wrapped_state, default_strategy, meta
end

#continue?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/workflow_template/state/intermediate.rb', line 18

def continue?
  !(error? || halted?)
end

#finalObject



26
27
28
# File 'lib/workflow_template/state/intermediate.rb', line 26

def final
  Final.new(wrapped_state, meta, self.class)
end

#halted?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/workflow_template/state/intermediate.rb', line 22

def halted?
  !!bare_state[:halted]
end

#initialize(wrapped_state, default_strategy, meta) ⇒ Object



11
12
13
14
# File 'lib/workflow_template/state/intermediate.rb', line 11

def initialize(wrapped_state, default_strategy, meta)
  @default_strategy = default_strategy
  super(wrapped_state, meta)
end

#merge_error(error, action) ⇒ Object



37
38
39
40
41
42
# File 'lib/workflow_template/state/intermediate.rb', line 37

def merge_error(error, action)
  return wrapped_state if error?

  wrapped_state = self.class.wrap_error_with_bare_state(error, {})
  process_wrapped_result(wrapped_state, action, trace: true, validate: false)
end

#normalize_data(normalizer) ⇒ Object



44
45
46
47
# File 'lib/workflow_template/state/intermediate.rb', line 44

def normalize_data(normalizer)
  wrapped_state = normalize(normalizer)
  self.class.send :new, wrapped_state, default_strategy, meta
end

#process_bare_result(bare_result, action, trace:, validate:) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/workflow_template/state/intermediate.rb', line 49

def process_bare_result(bare_result, action, trace:, validate:)
  process_result(action, trace, validate) do |strategy, action_name|
    self.class.map_unwrappable_state(wrapped_state) do |bare_state|
      self.class.merge_bare_result(bare_state, bare_result, strategy, action_name)
    end
  end
end

#process_wrapped_result(wrapped_result, action, trace:, validate:) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/workflow_template/state/intermediate.rb', line 57

def process_wrapped_result(wrapped_result, action, trace:, validate:)
  process_result(action, trace, validate) do |strategy, action_name|
    if wrapped_result.nil?
      raise Fatal::UnexpectedNil, action_name if strategy == :update

      wrapped_state
    else
      raise Fatal::BadActionReturn.new(action_name, wrapped_result) unless self.class.canonical?(wrapped_result)

      self.class.flat_map_unwrappable_state(wrapped_state) do |bare_state|
        self.class.map_unwrappable_state(wrapped_result) do |bare_result|
          self.class.merge_bare_result(bare_state, bare_result, strategy, action_name)
        end
      end
    end
  end
end

#state_classObject



75
76
77
# File 'lib/workflow_template/state/intermediate.rb', line 75

def state_class
  self.class
end