Module: Foobara::CommandPatternImplementation::Concerns::Runtime

Includes:
Foobara::Concern
Defined in:
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/runtime.rb,
foobara-0.7.3/projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/runtime.rb

Defined Under Namespace

Modules: ClassMethods Classes: CannotHaltWithoutAddingErrors, Halt

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Foobara::Concern

foobara_class_methods_module_for, foobara_concern?, included

Instance Attribute Details

#exception ⇒ Object (readonly)

Returns the value of attribute exception.



20
21
22
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 20

def exception
  @exception
end

#outcome ⇒ Object (readonly)

Returns the value of attribute outcome.



20
21
22
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 20

def outcome
  @outcome
end

#raw_result ⇒ Object

Returns the value of attribute raw_result.



21
22
23
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 21

def raw_result
  @raw_result
end

Instance Method Details

#halt! ⇒ Object

Raises:



57
58
59
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 57

def halt!
  raise Halt
end

#run ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 27

def run
  Foobara::Namespace.use self.class do
    _run_all_steps
  end

  @outcome
rescue Halt
  return outcome if state_machine.currently_errored?

  if error_collection.empty?
    # simplecov:disable
    raise CannotHaltWithoutAddingErrors, "Cannot halt without adding errors first. " \
                                         "Either add errors or use error! transition instead."
    # simplecov:enable
  end

  state_machine.fail!

  @outcome = Outcome.errors(error_collection)
rescue => e
  @exception = e
  rollback_transaction
  state_machine.error!
  raise
end

#run! ⇒ Object



23
24
25
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 23

def run!
  run.result!
end

#success? ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 53

def success?
  outcome&.success?
end

#validate_records ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/runtime.rb', line 5

def validate_records
  self.class.inputs_association_paths&.each do |data_path|
    if data_path.last == :"#"
      records = data_path.values_at(@inputs)

      records.each.with_index do |record, index|
        if record&.persisted? && !record.loaded?
          begin
            record.class.load(record)
          rescue Foobara::Entity::NotFoundError => e
            e.prepend_path!(index)
            e.prepend_path!(data_path.path[..-2])

            add_input_error(e)
          end
        end
      end
    else
      record = data_path.value_at(@inputs)

      if record&.persisted? && !record.loaded?
        begin
          record.class.load(record)
        rescue Foobara::Entity::NotFoundError => e
          e.prepend_path!(data_path)
          add_input_error(e)
        end
      end
    end
  end
end