Class: ROM::Factory::Builder Private
- Inherits:
-
Object
- Object
- ROM::Factory::Builder
- 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
- #attributes ⇒ ROM::Factory::Attributes readonly
-
#factories ⇒ Module
readonly
Factories with other builders.
- #relation ⇒ Object readonly private
- #struct_namespace(namespace) ⇒ Object readonly private
- #traits ⇒ Hash readonly
Instance Method Summary collapse
- #persistable ⇒ Object private
- #struct(*traits, **attrs) ⇒ Object (also: #create) private
- #tuple(*traits, **attrs) ⇒ Object private
- #tuple_evaluator ⇒ Object private
- #tuple_evaluator_relation ⇒ Object private
- #validate_keys(traits, tuple, allow_associations: false) ⇒ Object private
Instance Attribute Details
#attributes ⇒ ROM::Factory::Attributes (readonly)
17 |
# File 'lib/rom/factory/builder.rb', line 17 param :attributes |
#factories ⇒ Module (readonly)
Returns Factories with other builders.
33 |
# File 'lib/rom/factory/builder.rb', line 33 option :factories, reader: true, optional: true |
#relation ⇒ 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.
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 |
#traits ⇒ Hash (readonly)
21 |
# File 'lib/rom/factory/builder.rb', line 21 param :traits, default: -> { EMPTY_HASH } |
Instance Method Details
#persistable ⇒ 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.
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_evaluator ⇒ 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.
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_relation ⇒ 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.
72 73 74 |
# File 'lib/rom/factory/builder.rb', line 72 def tuple_evaluator_relation [:relation].struct_namespace([: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 |