Class: ROM::Factory::Attributes::Association::ManyToMany Private
- Defined in:
- lib/rom/factory/attributes/association.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.
Direct Known Subclasses
Instance Method Summary collapse
- #call(attrs = EMPTY_HASH, parent, persist: true) ⇒ Object private
- #dependency?(rel) ⇒ Boolean private
- #result(structs) ⇒ Object private
- #through? ⇒ Boolean private
- #through_factory? ⇒ Boolean private
- #through_factory_name ⇒ Object private
Constructor Details
This class inherits a constructor from ROM::Factory::Attributes::Association::Core
Instance Method Details
#call(attrs = EMPTY_HASH, parent, persist: true) ⇒ 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.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/rom/factory/attributes/association.rb', line 146 def call(attrs = EMPTY_HASH, parent, persist: true) return if attrs.key?(name) structs = count.times.map do if persist && attrs[tpk] attrs elsif persist builder.persistable.create(*traits, **attrs) else builder.struct(*traits, **attrs) end end # Delegate to through factory if it exists if persist if through_factory? structs.each do |child| through_attrs = { ::ROM::Inflector.singularize(assoc.source.name.key).to_sym => parent, assoc.through.assoc_name => child } factories[through_factory_name, **through_attrs] end else assoc.persist([parent], structs) end {name => result(structs)} else result(structs) end end |
#dependency?(rel) ⇒ Boolean
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.
182 |
# File 'lib/rom/factory/attributes/association.rb', line 182 def dependency?(rel) = assoc.source == rel |
#result(structs) ⇒ 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.
180 |
# File 'lib/rom/factory/attributes/association.rb', line 180 def result(structs) = {name => structs} |
#through? ⇒ Boolean
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.
184 |
# File 'lib/rom/factory/attributes/association.rb', line 184 def through? = true |
#through_factory? ⇒ Boolean
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.
186 187 188 |
# File 'lib/rom/factory/attributes/association.rb', line 186 def through_factory? factories.registry.key?(through_factory_name) end |
#through_factory_name ⇒ 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.
190 191 192 |
# File 'lib/rom/factory/attributes/association.rb', line 190 def through_factory_name ::ROM::Inflector.singularize(assoc.definition.through.source).to_sym end |