Class: Foobara::DomainMapper

Inherits:
Object
  • Object
show all
Includes:
CommandPatternImplementation
Defined in:
foobara-0.5.8/projects/domain_mapper/src/domain_mapper.rb,
foobara-0.5.8/projects/domain_mapper/lib/foobara/domain_mapper.rb

Overview

NOTE: If you depend_on a domain mapper in a command, then you need to depend on all domain mappers that that command uses. Or you can just exclude all of them in which case Foobara won’t enforce explicit depends_on of domain mappers.

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary

Attributes included from CommandPatternImplementation::Concerns::Subcommands

#is_subcommand

Attributes included from CommandPatternImplementation::Concerns::Runtime

#exception, #outcome, #raw_result

Attributes included from CommandPatternImplementation::Concerns::Errors

#error_collection

Attributes included from CommandPatternImplementation::Concerns::Inputs

#inputs, #raw_inputs

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods included from CommandPatternImplementation::Concerns::DomainMappers

#domain_map, #domain_map!, #run_mapped_subcommand!

Methods included from CommandPatternImplementation::Concerns::Subcommands

#subcommand?, #verify_depends_on!

Methods included from CommandPatternImplementation::Concerns::Entities

#load_entities, #load_records

Methods included from CommandPatternImplementation::Concerns::Transactions

#relevant_entity_classes

Methods included from NestedTransactionable

#auto_detect_current_transactions, #commit_transaction, #commit_transaction_if_open, #open_transaction, #opened_transactions, #relevant_entity_classes, relevant_entity_classes_for_type, #relevant_entity_classes_for_type, #rollback_transaction, #transactions, #use_transaction, with_needed_transactions_for_type

Methods included from CommandPatternImplementation::Concerns::StateMachine

#state_machine

Methods included from CommandPatternImplementation::Concerns::Callbacks

#state_machine_callback_registry

Methods included from CommandPatternImplementation::Concerns::Runtime

#halt!, #run, #run!, #success?

Methods included from CommandPatternImplementation::Concerns::Errors

#has_errors?, #initialize

Methods included from CommandPatternImplementation::Concerns::Inputs

#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?

Methods included from CommandPatternImplementation::Concerns::ResultType

#result_type

Methods included from CommandPatternImplementation::Concerns::InputsType

#inputs_type

Methods included from TruncatedInspect

#inspect, truncating

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs

Class Method Details

.applicable?(from_value, to_value) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'projects/domain_mapper/src/domain_mapper.rb', line 43

def applicable?(from_value, to_value)
  matches?(from_type, from_value) && matches?(to_type, to_value)
end

.applicable_score(from_value, to_value) ⇒ Object



51
52
53
# File 'projects/domain_mapper/src/domain_mapper.rb', line 51

def applicable_score(from_value, to_value)
  [*match_score(from_type, from_value), *match_score(to_type, to_value)].sum
end

.foobara_on_registerObject



9
10
11
# File 'projects/domain_mapper/src/domain_mapper.rb', line 9

def foobara_on_register
  foobara_domain.new_mapper_registered!
end

.fromObject

A bit hacky because Command only supports attributes inputs at the moment, ugg.



22
23
24
25
26
27
28
# File 'projects/domain_mapper/src/domain_mapper.rb', line 22

def from(...)
  from_type = args_to_type(...)

  inputs do
    from from_type, :required
  end
end

.from_typeObject



35
36
37
# File 'projects/domain_mapper/src/domain_mapper.rb', line 35

def from_type
  inputs_type.element_types[:from]
end

.install!Object



6
7
8
9
# File 'projects/domain_mapper/lib/foobara/domain_mapper.rb', line 6

def install!
  Namespace.global.foobara_add_category_for_subclass_of(:domain_mapper, self)
  Domain::DomainModuleExtension.include Foobara::DomainMapperLookups
end

.map(value) ⇒ Object



13
14
15
# File 'projects/domain_mapper/src/domain_mapper.rb', line 13

def map(value)
  new(from: value).run
end

.map!(value) ⇒ Object



17
18
19
# File 'projects/domain_mapper/src/domain_mapper.rb', line 17

def map!(value)
  new(from: value).run!
end

.matches?(type_indicator, value) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'projects/domain_mapper/src/domain_mapper.rb', line 47

def matches?(type_indicator, value)
  match_score(type_indicator, value)&.>(0)
end

.toObject



30
31
32
33
# File 'projects/domain_mapper/src/domain_mapper.rb', line 30

def to(...)
  result_type = args_to_type(...)
  result(result_type)
end

.to_typeObject



39
40
41
# File 'projects/domain_mapper/src/domain_mapper.rb', line 39

def to_type
  result_type
end

Instance Method Details

#executeObject



117
118
119
# File 'projects/domain_mapper/src/domain_mapper.rb', line 117

def execute
  map
end

#fromObject



121
122
123
# File 'projects/domain_mapper/src/domain_mapper.rb', line 121

def from
  inputs[:from]
end

#mapObject



125
126
127
128
129
# File 'projects/domain_mapper/src/domain_mapper.rb', line 125

def map
  # :nocov:
  raise "subclass responsibility"
  # :nocov:
end