rom-factory 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 946c06da46cc1d12ac8e90fc8b79661ce43e9ed2ab2ba0e3ffd93f5c1ac7e419
4
- data.tar.gz: fa2c475a578ba75f7574ed5d883a4432fc4f2328849fc4be74813b854a0c6dba
3
+ metadata.gz: 76c2c2d443aae25366e10dc9cfb41bc23a9e69abd38597b144214a9b4f861b51
4
+ data.tar.gz: 3aea3e8cf8568962e72c0d8ebda1da5b9ca38b6bcbf6469a9c2ea3f67377a314
5
5
  SHA512:
6
- metadata.gz: b1dea330b287e3b56c2acaea898c9139317b0de709098c0c7525d05215db34571dfa41447337ca39b39f7d1d5ace98fde9f442854a725870fa6496c24d00eee3
7
- data.tar.gz: 6279eb190440aeb10dc03c26fe18cfcc67f846e8d0981b7822746172f564936f5d2fd7cbf41a68336be1865516afda03947302804db8d6a1e05040198137beb9
6
+ metadata.gz: 1a463af2b73eca8c24d2a276c678a72e7d7883ed030b241bdc71c58998ce2ce0742f039e30744a0baa12d81cfcab111602f2b960e0db5abf786b3c0f9afe3c03
7
+ data.tar.gz: b60e2dfd2d87136bd3f10a84df790fa2f664babdd9d972682986545ceefabf7353f7811ef6f2f51028f611012e3b9f632cf485fcdf63c0d490ef543b9b59cf8d
data/CHANGELOG.md CHANGED
@@ -1,7 +1,53 @@
1
- <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
1
+ # Changelog
2
2
 
3
- ## 0.13.0 2025-01-21
3
+ All notable changes to this project will be documented in this file.
4
4
 
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Break Versioning](https://www.taoensso.com/break-versioning).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+
12
+ ### Changed
13
+
14
+ ### Deprecated
15
+
16
+ ### Removed
17
+
18
+ ### Fixed
19
+
20
+ ### Security
21
+
22
+ [Unreleased]: https://github.com/rom-rb/rom-factory/compare/v0.14.0...main
23
+
24
+ ## [0.14.0] - 2026-10-03
25
+
26
+ ### Added
27
+
28
+ - Support transient attributes. (@rickenharp in #97)
29
+
30
+ Define transient attributes inside a `transient` block. Other attributes can depend on them, but they are not part of the resulting tuple or struct. You can override them when building, like any other attribute.
31
+
32
+ ```ruby
33
+ Factory.define(:user) do |f|
34
+ f.transient do |t|
35
+ t.password "secret"
36
+ end
37
+ f.password_hash { |password| BCrypt::Password.create(password) }
38
+ end
39
+
40
+ Factory[:user, password: "something else"]
41
+ ```
42
+
43
+ ### Changed
44
+
45
+ - Minimum Ruby version is now 3.3. (@alassek)
46
+ - Add `tsort` as an explicit runtime dependency. (@flash-gordon)
47
+
48
+ [0.13.0]: https://github.com/rom-rb/rom-factory/compare/v0.13.0...v0.14.0
49
+
50
+ ## [0.13.0] - 2025-01-21
5
51
 
6
52
  ### Added
7
53
 
@@ -23,15 +69,18 @@ Factory.define :category do |f|
23
69
  end
24
70
  ```
25
71
 
72
+ - Aliases for factory methods (via #92) (@cflipse)
73
+
74
+ `Factory.create` is aliased to `Factory.[]`
75
+ `Factory.build` is aliased to `Factory.structs[]`
26
76
 
27
77
  ### Changed
28
78
 
29
79
  - Minimum Ruby version is now 3.1 (@flash-gordon)
30
80
 
31
- [Compare v0.12.0...v0.13.0](https://github.com/rom-rb/rom-factory/compare/v0.12.0...v0.13.0)
32
-
33
- ## 0.12.0 2024-01-19
81
+ [0.13.0]: https://github.com/rom-rb/rom-factory/compare/v0.12.0...v0.13.0
34
82
 
83
+ ## [0.12.0] - 2024-01-19
35
84
 
36
85
  ### Added
37
86
 
@@ -43,11 +92,9 @@ end
43
92
  - Relations without PKs should work too (via #87) (@solnic)
44
93
  - Relations with PK values generated on the Ruby side should work in SQlite too (via #87) (@solnic)
45
94
 
95
+ [0.12.0]: https://github.com/rom-rb/rom-factory/compare/v0.11.0...v0.12.0
46
96
 
47
- [Compare v0.11.0...v0.12.0](https://github.com/rom-rb/rom-factory/compare/v0.11.0...v0.12.0)
48
-
49
- ## 0.11.0 2022-11-11
50
-
97
+ ## [0.11.0] - 2022-11-11
51
98
 
52
99
  ### Added
53
100
 
@@ -80,20 +127,17 @@ Factory[:user, **user_attributes]
80
127
  - Upgraded to the latest versions of dry-rb dependencies, compatible with rom 5.3 (@flash-gordon)
81
128
  - Support for Faker 1.x was dropped (@alassek)
82
129
 
83
- [Compare v0.10.2...v0.11.0](https://github.com/rom-rb/rom-factory/compare/v0.10.2...v0.11.0)
84
-
85
- ## 0.10.2 2020-04-05
130
+ [0.11.0]: https://github.com/rom-rb/rom-factory/compare/v0.10.2...v0.11.0
86
131
 
132
+ ## [0.10.2] - 2020-04-05
87
133
 
88
134
  ### Fixed
89
135
 
90
136
  - Fix more keyword warnings (@flash-gordon)
91
137
 
138
+ [0.10.2]: https://github.com/rom-rb/rom-factory/compare/v0.10.1...v0.10.2
92
139
 
93
- [Compare v0.10.1...v0.10.2](https://github.com/rom-rb/rom-factory/compare/v0.10.1...v0.10.2)
94
-
95
- ## 0.10.1 2019-12-28
96
-
140
+ ## [0.10.1] - 2019-12-28
97
141
 
98
142
  ### Added
99
143
 
@@ -103,11 +147,9 @@ Factory[:user, **user_attributes]
103
147
 
104
148
  - Keyword warnings reported by Ruby 2.7 (@flash-gordon)
105
149
 
150
+ [0.10.1]: https://github.com/rom-rb/rom-factory/compare/v0.10.0...v0.10.1
106
151
 
107
- [Compare v0.10.0...v0.10.1](https://github.com/rom-rb/rom-factory/compare/v0.10.0...v0.10.1)
108
-
109
- ## 0.10.0 2019-12-11
110
-
152
+ ## [0.10.0] - 2019-12-11
111
153
 
112
154
  ### Added
113
155
 
@@ -124,41 +166,33 @@ Factory[:user, **user_attributes]
124
166
  - Support building structs when child assoc does not define parent (@psparrow)
125
167
  - Fixed `TupleEvaluator#struct_attrs` for non-standard output schema (@AMHOL)
126
168
 
169
+ [0.10.0]: https://github.com/rom-rb/rom-factory/compare/v0.9.1...v0.10.0
127
170
 
128
- [Compare v0.9.1...v0.10.0](https://github.com/rom-rb/rom-factory/compare/v0.9.1...v0.10.0)
129
-
130
- ## 0.9.1 2019-10-23
131
-
171
+ ## [0.9.1] - 2019-10-23
132
172
 
133
173
  ### Fixed
134
174
 
135
175
  - Attributes of a struct are no longer accidentally passed to their associations (@psparrow)
136
176
 
177
+ [0.9.1]: https://github.com/rom-rb/rom-factory/compare/v0.9.0...v0.9.1
137
178
 
138
- [Compare v0.9.0...v0.9.1](https://github.com/rom-rb/rom-factory/compare/v0.9.0...v0.9.1)
139
-
140
- ## 0.9.0 2019-08-12
141
-
179
+ ## [0.9.0] - 2019-08-12
142
180
 
143
181
  ### Added
144
182
 
145
183
  - When attributes hash includes unknown attributes, a `ROM::Factory::UnknownAttributeError` will be raised (@rawburt)
146
184
 
185
+ [0.9.0]: https://github.com/rom-rb/rom-factory/compare/v0.8.0...v0.9.0
147
186
 
148
- [Compare v0.8.0...v0.9.0](https://github.com/rom-rb/rom-factory/compare/v0.8.0...v0.9.0)
149
-
150
- ## 0.8.0 2019-04-24
151
-
187
+ ## [0.8.0] - 2019-04-24
152
188
 
153
189
  ### Fixed
154
190
 
155
191
  - Loaded association structs are no longer rejected by output schemas (issue #34) (flash-gordon + solnic)
156
192
 
193
+ [0.8.0]: https://github.com/rom-rb/rom-factory/compare/v0.7.0...v0.8.0
157
194
 
158
- [Compare v0.7.0...v0.8.0](https://github.com/rom-rb/rom-factory/compare/v0.7.0...v0.8.0)
159
-
160
- ## 0.7.0 2018-11-17
161
-
195
+ ## [0.7.0] - 2018-11-17
162
196
 
163
197
  ### Added
164
198
 
@@ -169,11 +203,9 @@ Factory[:user, **user_attributes]
169
203
 
170
204
  - Overwritten attributes with dependencies (JanaVPetrova)
171
205
 
206
+ [0.7.0]: https://github.com/rom-rb/rom-factory/compare/v0.6.0...v0.7.0
172
207
 
173
- [Compare v0.6.0...v0.7.0](https://github.com/rom-rb/rom-factory/compare/v0.6.0...v0.7.0)
174
-
175
- ## 0.6.0 2018-01-31
176
-
208
+ ## [0.6.0] - 2018-01-31
177
209
 
178
210
  ### Added
179
211
 
@@ -187,10 +219,9 @@ Factory[:user, **user_attributes]
187
219
 
188
220
  - Accessing a factory which is not defined will result in `FactoryNotDefinedError` exception (GustavoCaso + solnic)
189
221
 
190
- [Compare v0.5.0...v0.6.0](https://github.com/rom-rb/rom-factory/compare/v0.5.0...v0.6.0)
191
-
192
- ## 0.5.0 2017-10-24
222
+ [0.6.0]: https://github.com/rom-rb/rom-factory/compare/v0.5.0...v0.6.0
193
223
 
224
+ ## [0.5.0] - 2017-10-24
194
225
 
195
226
  ### Added
196
227
 
@@ -203,9 +234,9 @@ Factory[:user, **user_attributes]
203
234
 
204
235
  - Depends on `rom-core` now (solnic)
205
236
 
206
- [Compare v0.4.0...v0.5.0](https://github.com/rom-rb/rom-factory/compare/v0.4.0...v0.5.0)
237
+ [0.5.0]: https://github.com/rom-rb/rom-factory/compare/v0.4.0...v0.5.0
207
238
 
208
- ## 0.4.0 2017-03-03
239
+ ## [0.4.0] - 2017-03-03
209
240
 
210
241
  improves internals.
211
242
 
@@ -224,3 +255,5 @@ improves internals.
224
255
  - `Rom::Factory::Config.configure` was replaced with `ROM::Factory.configure` (solnic)
225
256
  - Global factory config and builders are gone (solnic)
226
257
  - Structs are now based on dry-struct (solnic)
258
+
259
+ [0.4.0]: https://github.com/rom-rb/rom-factory/tree/v0.4.0
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2021 rom-rb team
3
+ Copyright (c) 2015-2026 Hanakai team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,29 +1,22 @@
1
- [gem]: https://rubygems.org/gems/rom-factory
2
- [actions]: https://github.com/rom-rb/rom-factory/actions
3
- [codacy]: https://www.codacy.com/gh/rom-rb/rom-factory
4
- [chat]: https://rom-rb.zulipchat.com
5
- [inchpages]: http://inch-ci.org/github/rom-rb/rom-factory
1
+ <!--- This file is synced from hanakai-rb/repo-sync -->
6
2
 
7
- # rom-factory [![Join the chat at https://rom-rb.zulipchat.com](https://img.shields.io/badge/rom--rb-join%20chat-%23346b7a.svg)][chat]
3
+ [actions]: https://github.com/hanakai-rb/rom-factory/actions
4
+ [chat]: https://discord.gg/naQApPAsZB
5
+ [forum]: https://discourse.hanakai.org
6
+ [rubygem]: https://rubygems.org/gems/rom-factory
8
7
 
9
- [![Gem Version](https://badge.fury.io/rb/rom-factory.svg)][gem]
10
- [![CI Status](https://github.com/rom-rb/rom-factory/workflows/ci/badge.svg)][actions]
11
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/5fd26fae687549218458879b1a607e18)][codacy]
12
- [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/5fd26fae687549218458879b1a607e18)][codacy]
13
- [![Inline docs](http://inch-ci.org/github/rom-rb/rom-factory.svg?branch=master)][inchpages]
8
+ # ROM Factory [![Gem Version](https://badge.fury.io/rb/rom-factory.svg)][rubygem] [![CI Status](https://github.com/hanakai-rb/rom-factory/workflows/CI/badge.svg)][actions]
14
9
 
15
- ## Links
16
-
17
- * [User documentation](https://rom-rb.org/learn/factory)
18
- * [API documentation](https://rubydoc.info/gems/rom-factory)
10
+ [![Forum](https://img.shields.io/badge/Forum-dc360f?logo=discourse&logoColor=white)][forum]
11
+ [![Chat](https://img.shields.io/badge/Chat-717cf8?logo=discord&logoColor=white)][chat]
19
12
 
20
- ## Supported Ruby versions
13
+ ## Links
21
14
 
22
- This library officially supports the following Ruby versions:
15
+ - [User documentation](https://hanakai.org/learn/rom/factories)
16
+ - [API documentation](http://rubydoc.info/gems/rom-factory)
23
17
 
24
- * MRI >= `3.1`
25
- * jruby >= `9.4` (not tested in CI)
26
18
 
27
19
  ## License
28
20
 
29
21
  See `LICENSE` file.
22
+
@@ -1,205 +1,213 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ROM::Factory
4
- module Attributes
5
- # @api private
6
- # rubocop:disable Style/OptionalArguments
7
- module Association
8
- class << self
9
- def new(assoc, ...)
10
- const_get(assoc.definition.type).new(assoc, ...)
11
- end
12
- end
13
-
3
+ module ROM
4
+ module Factory
5
+ module Attributes
14
6
  # @api private
15
- class Core
16
- attr_reader :assoc, :options, :traits
17
-
18
- # @api private
19
- def initialize(assoc, builder, *traits, **options)
20
- @assoc = assoc
21
- @builder_proc = builder
22
- @traits = traits
23
- @options = options
7
+ # rubocop:disable Style/OptionalArguments
8
+ module Association
9
+ class << self
10
+ def new(assoc, ...)
11
+ const_get(assoc.definition.type).new(assoc, ...)
12
+ end
24
13
  end
25
14
 
26
15
  # @api private
27
- def through? = false
16
+ class Core
17
+ attr_reader :assoc, :options, :traits
28
18
 
29
- # @api private
30
- def builder
31
- @__builder__ ||= @builder_proc.call
32
- end
19
+ def transient
20
+ false
21
+ end
33
22
 
34
- # @api private
35
- def name = assoc.key
23
+ # @api private
24
+ def initialize(assoc, builder, *traits, **options)
25
+ @assoc = assoc
26
+ @builder_proc = builder
27
+ @traits = traits
28
+ @options = options
29
+ end
36
30
 
37
- # @api private
38
- def dependency?(*) = false
31
+ # @api private
32
+ def through? = false
39
33
 
40
- # @api private
41
- def value? = false
34
+ # @api private
35
+ def builder
36
+ @__builder__ ||= @builder_proc.call
37
+ end
42
38
 
43
- # @api private
44
- def factories = builder.factories
39
+ # @api private
40
+ def name = assoc.key
45
41
 
46
- # @api private
47
- def foreign_key = assoc.foreign_key
42
+ # @api private
43
+ def dependency?(*) = false
48
44
 
49
- # @api private
50
- def count = options.fetch(:count, 1)
51
- end
45
+ # @api private
46
+ def value? = false
52
47
 
53
- # @api private
54
- class ManyToOne < Core
55
- # @api private
56
- # rubocop:disable Metrics/AbcSize
57
- def call(attrs, persist: true)
58
- return if attrs.key?(name) && attrs[name].nil?
59
-
60
- assoc_data = attrs.fetch(name, EMPTY_HASH)
61
-
62
- if assoc_data.is_a?(::Hash) && assoc_data[assoc.target.primary_key] && !attrs[foreign_key]
63
- assoc.associate(attrs, attrs[name])
64
- elsif assoc_data.is_a?(::ROM::Struct)
65
- assoc.associate(attrs, assoc_data)
66
- else
67
- parent =
68
- if persist && !attrs[foreign_key]
69
- builder.persistable.create(*parent_traits, **assoc_data)
70
- else
71
- builder.struct(
72
- *parent_traits,
73
- **assoc_data, assoc.target.primary_key => attrs[foreign_key]
74
- )
75
- end
48
+ # @api private
49
+ def factories = builder.factories
76
50
 
77
- tuple = {name => parent}
51
+ # @api private
52
+ def foreign_key = assoc.foreign_key
78
53
 
79
- assoc.associate(tuple, parent)
80
- end
54
+ # @api private
55
+ def count = options.fetch(:count, 1)
81
56
  end
82
- # rubocop:enable Metrics/AbcSize
83
-
84
- private
85
57
 
86
- def parent_traits
87
- @parent_traits ||=
88
- if assoc.target.associations.key?(assoc.source.name)
89
- traits + [assoc.target.associations[assoc.source.name].key => false]
58
+ # @api private
59
+ class ManyToOne < Core
60
+ # @api private
61
+ # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
62
+ def call(attrs, persist: true)
63
+ return if attrs.key?(name) && attrs[name].nil?
64
+
65
+ assoc_data = attrs.fetch(name, EMPTY_HASH)
66
+
67
+ if assoc_data.is_a?(::Hash) && assoc_data[assoc.target.primary_key] && !attrs[foreign_key]
68
+ assoc.associate(attrs, attrs[name])
69
+ elsif assoc_data.is_a?(::ROM::Struct)
70
+ assoc.associate(attrs, assoc_data)
90
71
  else
91
- traits
72
+ parent =
73
+ if persist && !attrs[foreign_key]
74
+ builder.persistable.create(*parent_traits, **assoc_data)
75
+ else
76
+ builder.struct(
77
+ *parent_traits,
78
+ **assoc_data, assoc.target.primary_key => attrs[foreign_key]
79
+ )
80
+ end
81
+
82
+ tuple = {name => parent}
83
+
84
+ assoc.associate(tuple, parent)
92
85
  end
86
+ end
87
+ # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
88
+
89
+ private
90
+
91
+ def parent_traits
92
+ @parent_traits ||=
93
+ if assoc.target.associations.key?(assoc.source.name)
94
+ traits + [{assoc.target.associations[assoc.source.name].key => false}]
95
+ else
96
+ traits
97
+ end
98
+ end
93
99
  end
94
- end
95
100
 
96
- # @api private
97
- class OneToMany < Core
98
101
  # @api private
99
- def call(attrs = EMPTY_HASH, parent, persist: true)
100
- return if attrs.key?(name)
102
+ class OneToMany < Core
103
+ # @api private
104
+ def call(attrs = EMPTY_HASH, parent, persist: true)
105
+ return if attrs.key?(name)
101
106
 
102
- structs = ::Array.new(count).map do
103
- # hash which contains the foreign key info, i.e: { user_id: 1 }
104
- association_hash = assoc.associate(attrs, parent)
107
+ structs = ::Array.new(count).map do
108
+ # hash which contains the foreign key info, i.e: { user_id: 1 }
109
+ association_hash = assoc.associate(attrs, parent)
105
110
 
106
- if persist
107
- builder.persistable.create(*traits, **association_hash)
108
- else
109
- builder.struct(*traits, **attrs, **association_hash)
111
+ if persist
112
+ builder.persistable.create(*traits, **association_hash)
113
+ else
114
+ builder.struct(*traits, **attrs, **association_hash)
115
+ end
110
116
  end
117
+
118
+ {name => structs}
111
119
  end
112
120
 
113
- {name => structs}
121
+ # @api private
122
+ def dependency?(rel) = assoc.source == rel
114
123
  end
115
124
 
116
125
  # @api private
117
- def dependency?(rel) = assoc.source == rel
118
- end
119
-
120
- # @api private
121
- class OneToOne < OneToMany
122
- # @api private
123
- def call(attrs = EMPTY_HASH, parent, persist: true)
124
- # do not associate if count is 0
125
- return {name => nil} if count.zero?
126
+ class OneToOne < OneToMany
127
+ # @api private
128
+ def call(attrs = EMPTY_HASH, parent, persist: true)
129
+ # do not associate if count is 0
130
+ return {name => nil} if count.zero?
126
131
 
127
- return if attrs.key?(name)
132
+ return if attrs.key?(name)
128
133
 
129
- association_hash = assoc.associate(attrs, parent)
134
+ association_hash = assoc.associate(attrs, parent)
130
135
 
131
- struct =
132
- if persist
133
- builder.persistable.create(*traits, **association_hash)
134
- else
135
- belongs_to_name = ::ROM::Inflector.singularize(assoc.source_alias)
136
- belongs_to_associations = {belongs_to_name.to_sym => parent}
137
- final_attrs = attrs.merge(association_hash).merge(belongs_to_associations)
138
- builder.struct(*traits, **final_attrs)
139
- end
136
+ struct =
137
+ if persist
138
+ builder.persistable.create(*traits, **association_hash)
139
+ else
140
+ belongs_to_name = ::ROM::Inflector.singularize(assoc.source_alias)
141
+ belongs_to_associations = {belongs_to_name.to_sym => parent}
142
+ final_attrs = attrs.merge(association_hash).merge(belongs_to_associations)
143
+ builder.struct(*traits, **final_attrs)
144
+ end
140
145
 
141
- {name => struct}
146
+ {name => struct}
147
+ end
142
148
  end
143
- end
144
149
 
145
- class ManyToMany < Core
146
- def call(attrs = EMPTY_HASH, parent, persist: true)
147
- return if attrs.key?(name)
150
+ class ManyToMany < Core
151
+ # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
152
+ def call(attrs = EMPTY_HASH, parent, persist: true)
153
+ return if attrs.key?(name)
148
154
 
149
- structs = count.times.map do
150
- if persist && attrs[tpk]
151
- attrs
152
- elsif persist
153
- builder.persistable.create(*traits, **attrs)
154
- else
155
- builder.struct(*traits, **attrs)
155
+ structs = count.times.map do
156
+ if persist && attrs[tpk]
157
+ attrs
158
+ elsif persist
159
+ builder.persistable.create(*traits, **attrs)
160
+ else
161
+ builder.struct(*traits, **attrs)
162
+ end
156
163
  end
157
- end
158
-
159
- # Delegate to through factory if it exists
160
- if persist
161
- if through_factory?
162
- structs.each do |child|
163
- through_attrs = {
164
- ::ROM::Inflector.singularize(assoc.source.name.key).to_sym => parent,
165
- assoc.through.assoc_name => child
166
- }
167
164
 
168
- factories[through_factory_name, **through_attrs]
165
+ # Delegate to through factory if it exists
166
+ if persist
167
+ if through_factory?
168
+ structs.each do |child|
169
+ through_attrs = {
170
+ ::ROM::Inflector.singularize(assoc.source.name.key).to_sym => parent,
171
+ assoc.through.assoc_name => child
172
+ }
173
+
174
+ factories[through_factory_name, **through_attrs]
175
+ end
176
+ else
177
+ assoc.persist([parent], structs)
169
178
  end
179
+
180
+ {name => result(structs)}
170
181
  else
171
- assoc.persist([parent], structs)
182
+ result(structs)
172
183
  end
173
-
174
- {name => result(structs)}
175
- else
176
- result(structs)
177
184
  end
178
- end
185
+ # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
179
186
 
180
- def result(structs) = {name => structs}
187
+ def result(structs) = {name => structs}
181
188
 
182
- def dependency?(rel) = assoc.source == rel
189
+ def dependency?(rel) = assoc.source == rel
183
190
 
184
- def through? = true
191
+ def through? = true
185
192
 
186
- def through_factory?
187
- factories.registry.key?(through_factory_name)
188
- end
193
+ def through_factory?
194
+ factories.registry.key?(through_factory_name)
195
+ end
189
196
 
190
- def through_factory_name
191
- ::ROM::Inflector.singularize(assoc.definition.through.source).to_sym
192
- end
197
+ def through_factory_name
198
+ ::ROM::Inflector.singularize(assoc.definition.through.source).to_sym
199
+ end
193
200
 
194
- private
201
+ private
195
202
 
196
- def tpk = assoc.target.primary_key
197
- end
203
+ def tpk = assoc.target.primary_key
204
+ end
198
205
 
199
- class OneToOneThrough < ManyToMany
200
- def result(structs) = {name => structs[0]}
206
+ class OneToOneThrough < ManyToMany
207
+ def result(structs) = {name => structs[0]}
208
+ end
201
209
  end
202
210
  end
211
+ # rubocop:enable Style/OptionalArguments
203
212
  end
204
- # rubocop:enable Style/OptionalArguments
205
213
  end