Module: Foobara::EntitiesPlumbing

Defined in:
foobara-0.7.3/projects/entities_plumbing/lib/foobara/entities_plumbing.rb,
foobara-0.7.3/projects/entities_plumbing/src/command_connectors_extension.rb

Defined Under Namespace

Modules: CommandConnectorsExtension

Class Method Summary collapse

Class Method Details

.add_persistence_states_and_transitions ⇒ Object



25
26
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
52
53
54
55
56
57
58
# File 'projects/entities_plumbing/lib/foobara/entities_plumbing.rb', line 25

def add_persistence_states_and_transitions
  original_terminal_states = Command::StateMachine.terminal_states
  original_transition_map = Command::StateMachine.transition_map

  new_transition_map = {}

  new_transition_map[:initialized] = { open_transaction: :transaction_opened }
  new_transition_map[:transaction_opened] = { cast_and_validate_inputs: :inputs_casted_and_validated }
  new_transition_map[:inputs_casted_and_validated] = { load_records: :loaded_records }
  new_transition_map[:loaded_records] = { validate_records: :validated_records }
  new_transition_map[:validated_records] = { validate: :validated_execution }
  new_transition_map[:validated_execution] = {
    run_execute: original_transition_map[:validated_execution][:run_execute]
  }
  new_transition_map[:executing] = { commit_transaction: :transaction_committed }
  new_transition_map[:transaction_committed] = { succeed: :succeeded }

  new_transition_map[new_transition_map.keys] = {
    error: :errored,
    fail: :failed
  }

  [:succeeded, :errored, :failed].each do |state|
    new_transition_map[state] = original_transition_map[state]
  end

  Command::StateMachine.remove_all_callbacks
  Command::StateMachine.allow_recreating_callback_methods

  Command::StateMachine.set_transition_map(
    new_transition_map,
    terminal_states: original_terminal_states
  )
end

.install! ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'projects/entities_plumbing/lib/foobara/entities_plumbing.rb', line 4

def install!
  CommandPatternImplementation.include CommandPatternImplementation::Concerns::Transactions
  CommandPatternImplementation.include CommandPatternImplementation::Concerns::Entities
  CommandPatternImplementation.include CommandPatternImplementation::Concerns::EntityInputs
  CommandPatternImplementation.include CommandPatternImplementation::Concerns::EntityErrorsType
  CommandPatternImplementation.include CommandPatternImplementation::Concerns::EntityReflection
  CommandPatternImplementation.include CommandPatternImplementation::Concerns::TransactionalRuntime

  if Foobara.project_installed?("command_connectors")
    # simplecov:disable
    install_command_connector_extensions
    # simplecov:enable
  end
end

.install_command_connector_extensions ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'projects/entities_plumbing/lib/foobara/entities_plumbing.rb', line 60

def install_command_connector_extensions
  CommandConnector.singleton_class.prepend(
    Foobara::EntitiesPlumbing::CommandConnectorsExtension::ClassMethods
  )

  CommandConnector::Authenticator.include CommandConnector::AuthenticatorMethods
  CommandConnector::Request.include NestedTransactionable
  CommandRegistry::ExposedCommand.prepend CommandRegistry::ExposedCommandEntities

  project_path = "#{__dir__}/../.."

  Util.require_directory("#{project_path}/src/extensions/command_connector")
  Util.require_directory("#{project_path}/src/serializers")
  Util.require_directory("#{project_path}/src/transformers")
end

.new_project_added(new_project) ⇒ Object



19
20
21
22
23
# File 'projects/entities_plumbing/lib/foobara/entities_plumbing.rb', line 19

def new_project_added(new_project)
  if new_project.symbol == "command_connectors"
    install_command_connector_extensions
  end
end