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)



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

param :attributes

#factoriesModule (readonly)

Returns Factories with other builders.

Returns:

  • (Module)

    Factories with other builders



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

option :factories, reader: true, optional: true

#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.



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

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.



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

option :struct_namespace, reader: false

#traitsHash (readonly)

Returns:

  • (Hash)


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

param :traits, default: -> { EMPTY_HASH }

Instance Method Details

#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.



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

def persistable
  Persistable.new(self, relation)
end

#struct(*traits, **attrs) ⇒ 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
# File 'lib/rom/factory/builder.rb', line 41

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

  tuple_evaluator.struct(*traits, **attrs)
end

#tuple(*traits, **attrs) ⇒ 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.



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

def tuple(*traits, **attrs)
  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.



63
64
65
66
67
68
69
# File 'lib/rom/factory/builder.rb', line 63

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.



72
73
74
# File 'lib/rom/factory/builder.rb', line 72

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.



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

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 -= relation.schema.associations.to_h.keys if allow_associations

  raise UnknownFactoryAttributes, unknown_keys unless unknown_keys.empty?
end