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.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/rom/factory/attributes/association.rb', line 160 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 = { Dry::Core::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.
198 199 200 |
# File 'lib/rom/factory/attributes/association.rb', line 198 def dependency?(rel) assoc.source == rel end |
#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.
194 195 196 |
# File 'lib/rom/factory/attributes/association.rb', line 194 def result(structs) {name => structs} end |
#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.
202 203 204 |
# File 'lib/rom/factory/attributes/association.rb', line 202 def through? true end |
#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.
206 207 208 |
# File 'lib/rom/factory/attributes/association.rb', line 206 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.
210 211 212 |
# File 'lib/rom/factory/attributes/association.rb', line 210 def through_factory_name ROM::Inflector.singularize(assoc.definition.through.source).to_sym end |