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

#traitsHash (readonly)

Returns:

  • (Hash)


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

param :traits, default: -> { EMPTY_HASH }

Instance Method Details

#persistable(struct_namespace = ROM::Struct) ⇒ 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.



47
48
49
# File 'lib/rom/factory/builder.rb', line 47

def persistable(struct_namespace = ROM::Struct)
  Persistable.new(self, relation.struct_namespace(struct_namespace))
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.



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

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

#struct_namespace(namespace) ⇒ 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.



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

def struct_namespace(namespace)
  with(relation: relation.struct_namespace(namespace))
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.



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

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.



52
53
54
# File 'lib/rom/factory/builder.rb', line 52

def tuple_evaluator
  @__tuple_evaluator__ ||= TupleEvaluator.new(attributes, options[:relation], traits)
end

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



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

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

  raise UnknownFactoryAttributes, unknown_keys unless unknown_keys.empty?
end