Class: ROM::Factory::Builder Private

Inherits:
Object
  • Object
show all
Extended by:
Initializer
Includes:
Dry::Core::Constants
Defined in:
lib/rom/factory/builder.rb,
lib/rom/factory/builder/persistable.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Persistable

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesROM::Factory::Attributes (readonly)


19
# File 'lib/rom/factory/builder.rb', line 19

param :attributes

#relationObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


27
# File 'lib/rom/factory/builder.rb', line 27

option :relation, reader: false

#struct_namespace(namespace) ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


31
# File 'lib/rom/factory/builder.rb', line 31

option :struct_namespace, reader: false

#traitsHash (readonly)

Returns:

  • (Hash)

23
# File 'lib/rom/factory/builder.rb', line 23

param :traits, default: -> { EMPTY_HASH }

Instance Method Details

#extract_tuple(args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


79
80
81
# File 'lib/rom/factory/builder.rb', line 79

def extract_tuple(args)
  tuple_evaluator.extract_tuple(args)
end

#persistableObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


59
60
61
# File 'lib/rom/factory/builder.rb', line 59

def persistable
  Persistable.new(self, relation)
end

#struct(*args) ⇒ Object Also known as: create

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


41
42
43
44
45
46
# File 'lib/rom/factory/builder.rb', line 41

def struct(*args)
  traits, attrs = extract_tuple(args)
  validate_keys(traits, attrs, allow_associations: true)

  tuple_evaluator.struct(*args)
end

#tuple(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


34
35
36
37
38
# File 'lib/rom/factory/builder.rb', line 34

def tuple(*args)
  traits, attrs = extract_tuple(args)

  tuple_evaluator.defaults(traits, attrs)
end

#tuple_evaluatorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


64
65
66
# File 'lib/rom/factory/builder.rb', line 64

def tuple_evaluator
  @__tuple_evaluator__ ||= TupleEvaluator.new(attributes, tuple_evaluator_relation, traits)
end

#tuple_evaluator_relationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


69
70
71
# File 'lib/rom/factory/builder.rb', line 69

def tuple_evaluator_relation
  options[:relation].struct_namespace(options[:struct_namespace][:namespace])
end

#validate_keys(traits, tuple, allow_associations: false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


84
85
86
87
88
89
90
91
92
# File 'lib/rom/factory/builder.rb', line 84

def validate_keys(traits, tuple, allow_associations: false)
  schema_keys = relation.schema.attributes.map(&:name)
  assoc_keys = tuple_evaluator.assoc_names(traits)
  unknown_keys = tuple.keys - schema_keys - assoc_keys

  unknown_keys = unknown_keys - relation.schema.associations.to_h.keys if allow_associations

  raise UnknownFactoryAttributes, unknown_keys unless unknown_keys.empty?
end