nested_record 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +18 -21
- data/Appraisals +13 -3
- data/Gemfile.lock +36 -26
- data/README.md +118 -0
- data/gemfiles/rails_5.2.gemfile +1 -1
- data/gemfiles/rails_5.2.gemfile.lock +26 -26
- data/gemfiles/rails_6.0.gemfile +1 -1
- data/gemfiles/rails_6.0.gemfile.lock +27 -27
- data/gemfiles/rails_6.1.gemfile +1 -1
- data/gemfiles/rails_6.1.gemfile.lock +27 -27
- data/gemfiles/rails_7.0.gemfile +7 -0
- data/gemfiles/rails_7.0.gemfile.lock +56 -0
- data/gemfiles/rails_7.1.gemfile +7 -0
- data/gemfiles/rails_7.1.gemfile.lock +68 -0
- data/lib/nested_record/base.rb +3 -3
- data/lib/nested_record/collection_proxy.rb +2 -0
- data/lib/nested_record/lookup_const.rb +21 -3
- data/lib/nested_record/version.rb +1 -1
- data/lib/nested_record.rb +1 -0
- data/nested_record.gemspec +1 -1
- data/spec/support/model.rb +16 -2
- metadata +13 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0761ce9c739c3f58d9ee2b52552664015df2d6fb6aed4dab164dd33038fbc1fe
|
4
|
+
data.tar.gz: 2d63fb82c3be079c5de28599ca02d0d4ddeb20c5a82f554901601bbaa8b70011
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ff11ab93295ca0d08551e513f81b6f086c115c264c7c3ae7843fcb34dcae099b549f2501b9cad65425708593a018b76af00ab2e76339317dbd9ad57a759a9ef
|
7
|
+
data.tar.gz: d6cb9f2f8fcc4c7b958905e93690cb8f7e319fad664780e4e1abb311b15d66f7c6f28b756874a5f1035c31ecd2fcf03935ee35f711e66d411595a86ea66b6b65
|
data/.github/workflows/rspec.yml
CHANGED
@@ -12,17 +12,28 @@ jobs:
|
|
12
12
|
strategy:
|
13
13
|
matrix:
|
14
14
|
ruby:
|
15
|
-
- 2.
|
16
|
-
- 2.
|
17
|
-
-
|
18
|
-
- 3.
|
15
|
+
- "2.6"
|
16
|
+
- "2.7"
|
17
|
+
- "3.0"
|
18
|
+
- "3.1"
|
19
|
+
- "3.2"
|
19
20
|
gemfile:
|
20
21
|
- gemfiles/rails_5.2.gemfile
|
21
22
|
- gemfiles/rails_6.0.gemfile
|
22
23
|
- gemfiles/rails_6.1.gemfile
|
24
|
+
- gemfiles/rails_7.0.gemfile
|
25
|
+
- gemfiles/rails_7.1.gemfile
|
23
26
|
exclude:
|
24
27
|
- gemfile: gemfiles/rails_5.2.gemfile
|
25
|
-
ruby: 3.0
|
28
|
+
ruby: "3.0"
|
29
|
+
- gemfile: gemfiles/rails_5.2.gemfile
|
30
|
+
ruby: "3.1"
|
31
|
+
- gemfile: gemfiles/rails_5.2.gemfile
|
32
|
+
ruby: "3.2"
|
33
|
+
- gemfile: gemfiles/rails_7.0.gemfile
|
34
|
+
ruby: "2.6"
|
35
|
+
- gemfile: gemfiles/rails_7.1.gemfile
|
36
|
+
ruby: "2.6"
|
26
37
|
env:
|
27
38
|
BUNDLE_GEMFILE: ${{ format('{0}/{1}', github.workspace, matrix.gemfile) }}
|
28
39
|
BUNDLE_PATH: ${{ format('{0}/vendor/bundle', github.workspace) }}
|
@@ -31,23 +42,9 @@ jobs:
|
|
31
42
|
- name: Checkout
|
32
43
|
uses: actions/checkout@v1
|
33
44
|
- name: Setup ruby
|
34
|
-
uses:
|
45
|
+
uses: ruby/setup-ruby@v1
|
35
46
|
with:
|
36
47
|
ruby-version: ${{ matrix.ruby }}
|
37
|
-
|
38
|
-
run: gem install bundler:2.2.14
|
39
|
-
- name: Cache Bundler
|
40
|
-
uses: actions/cache@v1
|
41
|
-
id: cache-bundler
|
42
|
-
with:
|
43
|
-
path: vendor/bundle
|
44
|
-
key: ${{ runner.os }}-gem-${{ matrix.ruby }}-${{ hashFiles(format('{0}/{1}.lock', github.workspace, matrix.gemfile)) }}
|
45
|
-
restore-keys: |
|
46
|
-
${{ runner.os }}-gem-${{ matrix.ruby }}-
|
47
|
-
- name: Install Bundler dependencies
|
48
|
-
if: steps.cache-bundler.outputs.cache-hit != 'true'
|
49
|
-
run: bundle install --jobs=4
|
50
|
-
- name: Check Bunlder dependencies
|
51
|
-
run: bundle check
|
48
|
+
bundler-cache: true
|
52
49
|
- name: RSpec
|
53
50
|
run: bundle exec rspec
|
data/Appraisals
CHANGED
@@ -1,11 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
appraise "rails-5.2" do
|
2
|
-
gem 'activemodel', '~> 5.2.
|
4
|
+
gem 'activemodel', '~> 5.2.8.1'
|
3
5
|
end
|
4
6
|
|
5
7
|
appraise "rails-6.0" do
|
6
|
-
gem 'activemodel', '~> 6.0.
|
8
|
+
gem 'activemodel', '~> 6.0.6.1'
|
7
9
|
end
|
8
10
|
|
9
11
|
appraise "rails-6.1" do
|
10
|
-
gem 'activemodel', '~> 6.1.
|
12
|
+
gem 'activemodel', '~> 6.1.7.6'
|
13
|
+
end
|
14
|
+
|
15
|
+
appraise "rails-7.0" do
|
16
|
+
gem 'activemodel', '~> 7.0.8'
|
17
|
+
end
|
18
|
+
|
19
|
+
appraise "rails-7.1" do
|
20
|
+
gem 'activemodel', '~> 7.1.1'
|
11
21
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,47 +1,57 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nested_record (1.1.
|
5
|
-
activemodel (
|
4
|
+
nested_record (1.1.1)
|
5
|
+
activemodel (> 5.2, < 7.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (
|
11
|
-
activesupport (=
|
12
|
-
activesupport (
|
10
|
+
activemodel (7.1.1)
|
11
|
+
activesupport (= 7.1.1)
|
12
|
+
activesupport (7.1.1)
|
13
|
+
base64
|
14
|
+
bigdecimal
|
13
15
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
connection_pool (>= 2.2.5)
|
17
|
+
drb
|
14
18
|
i18n (>= 1.6, < 2)
|
15
19
|
minitest (>= 5.1)
|
20
|
+
mutex_m
|
16
21
|
tzinfo (~> 2.0)
|
17
|
-
|
18
|
-
appraisal (2.4.0)
|
22
|
+
appraisal (2.5.0)
|
19
23
|
bundler
|
20
24
|
rake
|
21
25
|
thor (>= 0.14.0)
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
base64 (0.1.1)
|
27
|
+
bigdecimal (3.1.4)
|
28
|
+
concurrent-ruby (1.2.2)
|
29
|
+
connection_pool (2.4.1)
|
30
|
+
diff-lcs (1.5.0)
|
31
|
+
drb (2.1.1)
|
32
|
+
ruby2_keywords
|
33
|
+
i18n (1.14.1)
|
25
34
|
concurrent-ruby (~> 1.0)
|
26
|
-
minitest (5.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
rspec-
|
31
|
-
rspec-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
minitest (5.20.0)
|
36
|
+
mutex_m (0.1.2)
|
37
|
+
rake (13.0.6)
|
38
|
+
rspec (3.12.0)
|
39
|
+
rspec-core (~> 3.12.0)
|
40
|
+
rspec-expectations (~> 3.12.0)
|
41
|
+
rspec-mocks (~> 3.12.0)
|
42
|
+
rspec-core (3.12.2)
|
43
|
+
rspec-support (~> 3.12.0)
|
44
|
+
rspec-expectations (3.12.3)
|
35
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
-
rspec-support (~> 3.
|
37
|
-
rspec-mocks (3.
|
46
|
+
rspec-support (~> 3.12.0)
|
47
|
+
rspec-mocks (3.12.6)
|
38
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-support (3.
|
41
|
-
|
42
|
-
|
49
|
+
rspec-support (~> 3.12.0)
|
50
|
+
rspec-support (3.12.1)
|
51
|
+
ruby2_keywords (0.0.5)
|
52
|
+
thor (1.2.2)
|
53
|
+
tzinfo (2.0.6)
|
43
54
|
concurrent-ruby (~> 1.0)
|
44
|
-
zeitwerk (2.4.2)
|
45
55
|
|
46
56
|
PLATFORMS
|
47
57
|
ruby
|
data/README.md
CHANGED
@@ -105,6 +105,124 @@ user.profile_attributes = {
|
|
105
105
|
}
|
106
106
|
```
|
107
107
|
|
108
|
+
## Advanced usage
|
109
|
+
|
110
|
+
`nested_record` can do many different things for you!
|
111
|
+
|
112
|
+
### Validations
|
113
|
+
|
114
|
+
Every `NestedRecord::Base` descendant in fact is an `ActiveModel::Model` so standard validations are also supported.
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
class Profile < NestedRecord::Base
|
118
|
+
attribute :age, :integer
|
119
|
+
attribute :active, :boolean
|
120
|
+
|
121
|
+
validates :age, presence: true
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
### Don't bother with defining record micro-classes
|
126
|
+
|
127
|
+
If you want so, you can rewrite the above example this way:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
class User < ApplicationRecord
|
131
|
+
has_one_nested :profile do
|
132
|
+
attribute :age, :integer
|
133
|
+
attribute :active, :boolean
|
134
|
+
has_one_nested :contacts do
|
135
|
+
attribute :email, :string
|
136
|
+
attribute :phone, :string
|
137
|
+
has_many_nested :socials do
|
138
|
+
attribute :name
|
139
|
+
attribute :url
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
```
|
145
|
+
|
146
|
+
Record classes then available under _local types_ namespace module e.g. `User::LocalTypes::Profile`.
|
147
|
+
|
148
|
+
### Concerns
|
149
|
+
|
150
|
+
Common attributes, validations and other settings can be DRY-ed to modules called _concerns_.
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
module TitleAndDescription
|
154
|
+
extend NestedRecord::Concern
|
155
|
+
|
156
|
+
attribute :title
|
157
|
+
attribute :description
|
158
|
+
|
159
|
+
validates :title, presence: true
|
160
|
+
end
|
161
|
+
|
162
|
+
class Article < NestedRecord::Base
|
163
|
+
has_one_nested :foo do
|
164
|
+
include TitleAndDescription
|
165
|
+
end
|
166
|
+
end
|
167
|
+
```
|
168
|
+
|
169
|
+
### `:class_name` option
|
170
|
+
|
171
|
+
By default, class name of nested record is automatically inferred from the association name but of course it's all customizable. There's a `:class_name` option for this!
|
172
|
+
|
173
|
+
Depending on what form do you use — `has_* :foo` or `has_* :foo do ... end`, the `:class_name` option means different things.
|
174
|
+
|
175
|
+
#### `:class_name` option when referring an external model
|
176
|
+
|
177
|
+
In a non-`&block` form, the `:class_name` behaves similar to the option with same name in ActiveRecord's `has_one`/`has_many` associations.
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
class User < ApplicationRecord
|
181
|
+
has_one_nested :profile, class_name: 'SomeNamespace::Profile'
|
182
|
+
end
|
183
|
+
|
184
|
+
class SomeNamespace::Profile < NestedRecord::Base
|
185
|
+
attribute :age, :integer
|
186
|
+
attribute :active, :boolean
|
187
|
+
end
|
188
|
+
```
|
189
|
+
|
190
|
+
#### `:class_name` option when using with an embedded _local types_
|
191
|
+
|
192
|
+
When record definition is embedded, `:class_name` option denotes the name of the class in _local types_ namespace module under which it's defined.
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
class User < ApplicationRecord
|
196
|
+
has_one_nested :profile, class_name: 'ProfileRecord' do
|
197
|
+
attribute :age, :integer
|
198
|
+
attribute :active, :boolean
|
199
|
+
end
|
200
|
+
end
|
201
|
+
```
|
202
|
+
|
203
|
+
Then the profile model is available under `User::LocalTypes::ProfileRecord` name.
|
204
|
+
|
205
|
+
You can also disable the const naming at all, passing `class_name: false`. In this case, the _local type_ is anonymous so no constant in _local types_ namespace is set.
|
206
|
+
|
207
|
+
`class_name: true` (the default) means infer the class name from association name e.g. `User::LocalTypes::Profile` constant is set by default.
|
208
|
+
|
209
|
+
### `nested_accessors`
|
210
|
+
|
211
|
+
This is the `store_accessor` on steroids! Unlike `store_accessor` it's support nesting, type coercions and all other things this library can do. Think of it as a `has_one_nested` association with accessors lifted up one level.
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
class User < ApplicationRecord
|
215
|
+
nested_accessors from: :profile do
|
216
|
+
attribute :age, :integer
|
217
|
+
attribute :active, :integer
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
user = User.new
|
222
|
+
user.age = 33
|
223
|
+
user.active = true
|
224
|
+
```
|
225
|
+
|
108
226
|
## Development
|
109
227
|
|
110
228
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/gemfiles/rails_5.2.gemfile
CHANGED
@@ -1,52 +1,52 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
nested_record (1.1.
|
5
|
-
activemodel (
|
4
|
+
nested_record (1.1.1)
|
5
|
+
activemodel (> 5.2, < 7.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (5.2.
|
11
|
-
activesupport (= 5.2.
|
12
|
-
activesupport (5.2.
|
10
|
+
activemodel (5.2.8.1)
|
11
|
+
activesupport (= 5.2.8.1)
|
12
|
+
activesupport (5.2.8.1)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 0.7, < 2)
|
15
15
|
minitest (~> 5.1)
|
16
16
|
tzinfo (~> 1.1)
|
17
|
-
appraisal (2.
|
17
|
+
appraisal (2.5.0)
|
18
18
|
bundler
|
19
19
|
rake
|
20
20
|
thor (>= 0.14.0)
|
21
|
-
concurrent-ruby (1.
|
22
|
-
diff-lcs (1.
|
23
|
-
i18n (1.
|
21
|
+
concurrent-ruby (1.2.2)
|
22
|
+
diff-lcs (1.5.0)
|
23
|
+
i18n (1.14.1)
|
24
24
|
concurrent-ruby (~> 1.0)
|
25
|
-
minitest (5.
|
26
|
-
rake (13.0.
|
27
|
-
rspec (3.
|
28
|
-
rspec-core (~> 3.
|
29
|
-
rspec-expectations (~> 3.
|
30
|
-
rspec-mocks (~> 3.
|
31
|
-
rspec-core (3.
|
32
|
-
rspec-support (~> 3.
|
33
|
-
rspec-expectations (3.
|
25
|
+
minitest (5.20.0)
|
26
|
+
rake (13.0.6)
|
27
|
+
rspec (3.12.0)
|
28
|
+
rspec-core (~> 3.12.0)
|
29
|
+
rspec-expectations (~> 3.12.0)
|
30
|
+
rspec-mocks (~> 3.12.0)
|
31
|
+
rspec-core (3.12.2)
|
32
|
+
rspec-support (~> 3.12.0)
|
33
|
+
rspec-expectations (3.12.3)
|
34
34
|
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
-
rspec-support (~> 3.
|
36
|
-
rspec-mocks (3.
|
35
|
+
rspec-support (~> 3.12.0)
|
36
|
+
rspec-mocks (3.12.6)
|
37
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
-
rspec-support (~> 3.
|
39
|
-
rspec-support (3.
|
40
|
-
thor (1.
|
38
|
+
rspec-support (~> 3.12.0)
|
39
|
+
rspec-support (3.12.1)
|
40
|
+
thor (1.3.0)
|
41
41
|
thread_safe (0.3.6)
|
42
|
-
tzinfo (1.2.
|
42
|
+
tzinfo (1.2.11)
|
43
43
|
thread_safe (~> 0.1)
|
44
44
|
|
45
45
|
PLATFORMS
|
46
46
|
ruby
|
47
47
|
|
48
48
|
DEPENDENCIES
|
49
|
-
activemodel (~> 5.2.
|
49
|
+
activemodel (~> 5.2.8.1)
|
50
50
|
appraisal
|
51
51
|
bundler (>= 2)
|
52
52
|
nested_record!
|
@@ -54,4 +54,4 @@ DEPENDENCIES
|
|
54
54
|
rspec (~> 3.0)
|
55
55
|
|
56
56
|
BUNDLED WITH
|
57
|
-
2.
|
57
|
+
2.3.22
|
data/gemfiles/rails_6.0.gemfile
CHANGED
@@ -1,54 +1,54 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
nested_record (1.1.
|
5
|
-
activemodel (
|
4
|
+
nested_record (1.1.1)
|
5
|
+
activemodel (> 5.2, < 7.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (6.0.
|
11
|
-
activesupport (= 6.0.
|
12
|
-
activesupport (6.0.
|
10
|
+
activemodel (6.0.6.1)
|
11
|
+
activesupport (= 6.0.6.1)
|
12
|
+
activesupport (6.0.6.1)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 0.7, < 2)
|
15
15
|
minitest (~> 5.1)
|
16
16
|
tzinfo (~> 1.1)
|
17
17
|
zeitwerk (~> 2.2, >= 2.2.2)
|
18
|
-
appraisal (2.
|
18
|
+
appraisal (2.5.0)
|
19
19
|
bundler
|
20
20
|
rake
|
21
21
|
thor (>= 0.14.0)
|
22
|
-
concurrent-ruby (1.
|
23
|
-
diff-lcs (1.
|
24
|
-
i18n (1.
|
22
|
+
concurrent-ruby (1.2.2)
|
23
|
+
diff-lcs (1.5.0)
|
24
|
+
i18n (1.14.1)
|
25
25
|
concurrent-ruby (~> 1.0)
|
26
|
-
minitest (5.
|
27
|
-
rake (13.0.
|
28
|
-
rspec (3.
|
29
|
-
rspec-core (~> 3.
|
30
|
-
rspec-expectations (~> 3.
|
31
|
-
rspec-mocks (~> 3.
|
32
|
-
rspec-core (3.
|
33
|
-
rspec-support (~> 3.
|
34
|
-
rspec-expectations (3.
|
26
|
+
minitest (5.20.0)
|
27
|
+
rake (13.0.6)
|
28
|
+
rspec (3.12.0)
|
29
|
+
rspec-core (~> 3.12.0)
|
30
|
+
rspec-expectations (~> 3.12.0)
|
31
|
+
rspec-mocks (~> 3.12.0)
|
32
|
+
rspec-core (3.12.2)
|
33
|
+
rspec-support (~> 3.12.0)
|
34
|
+
rspec-expectations (3.12.3)
|
35
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
-
rspec-support (~> 3.
|
37
|
-
rspec-mocks (3.
|
36
|
+
rspec-support (~> 3.12.0)
|
37
|
+
rspec-mocks (3.12.6)
|
38
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-support (3.
|
41
|
-
thor (1.
|
39
|
+
rspec-support (~> 3.12.0)
|
40
|
+
rspec-support (3.12.1)
|
41
|
+
thor (1.3.0)
|
42
42
|
thread_safe (0.3.6)
|
43
|
-
tzinfo (1.2.
|
43
|
+
tzinfo (1.2.11)
|
44
44
|
thread_safe (~> 0.1)
|
45
|
-
zeitwerk (2.
|
45
|
+
zeitwerk (2.6.12)
|
46
46
|
|
47
47
|
PLATFORMS
|
48
48
|
ruby
|
49
49
|
|
50
50
|
DEPENDENCIES
|
51
|
-
activemodel (~> 6.0.
|
51
|
+
activemodel (~> 6.0.6.1)
|
52
52
|
appraisal
|
53
53
|
bundler (>= 2)
|
54
54
|
nested_record!
|
@@ -56,4 +56,4 @@ DEPENDENCIES
|
|
56
56
|
rspec (~> 3.0)
|
57
57
|
|
58
58
|
BUNDLED WITH
|
59
|
-
|
59
|
+
2.4.20
|
data/gemfiles/rails_6.1.gemfile
CHANGED
@@ -1,53 +1,53 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
nested_record (1.1.
|
5
|
-
activemodel (
|
4
|
+
nested_record (1.1.1)
|
5
|
+
activemodel (> 5.2, < 7.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (6.1.
|
11
|
-
activesupport (= 6.1.
|
12
|
-
activesupport (6.1.
|
10
|
+
activemodel (6.1.7.6)
|
11
|
+
activesupport (= 6.1.7.6)
|
12
|
+
activesupport (6.1.7.6)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
16
16
|
tzinfo (~> 2.0)
|
17
17
|
zeitwerk (~> 2.3)
|
18
|
-
appraisal (2.
|
18
|
+
appraisal (2.5.0)
|
19
19
|
bundler
|
20
20
|
rake
|
21
21
|
thor (>= 0.14.0)
|
22
|
-
concurrent-ruby (1.
|
23
|
-
diff-lcs (1.
|
24
|
-
i18n (1.
|
22
|
+
concurrent-ruby (1.2.2)
|
23
|
+
diff-lcs (1.5.0)
|
24
|
+
i18n (1.14.1)
|
25
25
|
concurrent-ruby (~> 1.0)
|
26
|
-
minitest (5.
|
27
|
-
rake (13.0.
|
28
|
-
rspec (3.
|
29
|
-
rspec-core (~> 3.
|
30
|
-
rspec-expectations (~> 3.
|
31
|
-
rspec-mocks (~> 3.
|
32
|
-
rspec-core (3.
|
33
|
-
rspec-support (~> 3.
|
34
|
-
rspec-expectations (3.
|
26
|
+
minitest (5.20.0)
|
27
|
+
rake (13.0.6)
|
28
|
+
rspec (3.12.0)
|
29
|
+
rspec-core (~> 3.12.0)
|
30
|
+
rspec-expectations (~> 3.12.0)
|
31
|
+
rspec-mocks (~> 3.12.0)
|
32
|
+
rspec-core (3.12.2)
|
33
|
+
rspec-support (~> 3.12.0)
|
34
|
+
rspec-expectations (3.12.3)
|
35
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
-
rspec-support (~> 3.
|
37
|
-
rspec-mocks (3.
|
36
|
+
rspec-support (~> 3.12.0)
|
37
|
+
rspec-mocks (3.12.6)
|
38
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-support (3.
|
41
|
-
thor (1.
|
42
|
-
tzinfo (2.0.
|
39
|
+
rspec-support (~> 3.12.0)
|
40
|
+
rspec-support (3.12.1)
|
41
|
+
thor (1.3.0)
|
42
|
+
tzinfo (2.0.6)
|
43
43
|
concurrent-ruby (~> 1.0)
|
44
|
-
zeitwerk (2.
|
44
|
+
zeitwerk (2.6.12)
|
45
45
|
|
46
46
|
PLATFORMS
|
47
47
|
ruby
|
48
48
|
|
49
49
|
DEPENDENCIES
|
50
|
-
activemodel (~> 6.1.
|
50
|
+
activemodel (~> 6.1.7.6)
|
51
51
|
appraisal
|
52
52
|
bundler (>= 2)
|
53
53
|
nested_record!
|
@@ -55,4 +55,4 @@ DEPENDENCIES
|
|
55
55
|
rspec (~> 3.0)
|
56
56
|
|
57
57
|
BUNDLED WITH
|
58
|
-
|
58
|
+
2.4.20
|
@@ -0,0 +1,56 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
nested_record (1.1.1)
|
5
|
+
activemodel (> 5.2, < 7.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (7.0.8)
|
11
|
+
activesupport (= 7.0.8)
|
12
|
+
activesupport (7.0.8)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
appraisal (2.5.0)
|
18
|
+
bundler
|
19
|
+
rake
|
20
|
+
thor (>= 0.14.0)
|
21
|
+
concurrent-ruby (1.2.2)
|
22
|
+
diff-lcs (1.5.0)
|
23
|
+
i18n (1.14.1)
|
24
|
+
concurrent-ruby (~> 1.0)
|
25
|
+
minitest (5.20.0)
|
26
|
+
rake (13.0.6)
|
27
|
+
rspec (3.12.0)
|
28
|
+
rspec-core (~> 3.12.0)
|
29
|
+
rspec-expectations (~> 3.12.0)
|
30
|
+
rspec-mocks (~> 3.12.0)
|
31
|
+
rspec-core (3.12.2)
|
32
|
+
rspec-support (~> 3.12.0)
|
33
|
+
rspec-expectations (3.12.3)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.12.0)
|
36
|
+
rspec-mocks (3.12.6)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.12.0)
|
39
|
+
rspec-support (3.12.1)
|
40
|
+
thor (1.3.0)
|
41
|
+
tzinfo (2.0.6)
|
42
|
+
concurrent-ruby (~> 1.0)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
activemodel (~> 7.0.8)
|
49
|
+
appraisal
|
50
|
+
bundler (>= 2)
|
51
|
+
nested_record!
|
52
|
+
rake (~> 13.0)
|
53
|
+
rspec (~> 3.0)
|
54
|
+
|
55
|
+
BUNDLED WITH
|
56
|
+
2.4.20
|
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
nested_record (1.1.1)
|
5
|
+
activemodel (> 5.2, < 7.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (7.1.1)
|
11
|
+
activesupport (= 7.1.1)
|
12
|
+
activesupport (7.1.1)
|
13
|
+
base64
|
14
|
+
bigdecimal
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
connection_pool (>= 2.2.5)
|
17
|
+
drb
|
18
|
+
i18n (>= 1.6, < 2)
|
19
|
+
minitest (>= 5.1)
|
20
|
+
mutex_m
|
21
|
+
tzinfo (~> 2.0)
|
22
|
+
appraisal (2.5.0)
|
23
|
+
bundler
|
24
|
+
rake
|
25
|
+
thor (>= 0.14.0)
|
26
|
+
base64 (0.1.1)
|
27
|
+
bigdecimal (3.1.4)
|
28
|
+
concurrent-ruby (1.2.2)
|
29
|
+
connection_pool (2.4.1)
|
30
|
+
diff-lcs (1.5.0)
|
31
|
+
drb (2.1.1)
|
32
|
+
ruby2_keywords
|
33
|
+
i18n (1.14.1)
|
34
|
+
concurrent-ruby (~> 1.0)
|
35
|
+
minitest (5.20.0)
|
36
|
+
mutex_m (0.1.2)
|
37
|
+
rake (13.0.6)
|
38
|
+
rspec (3.12.0)
|
39
|
+
rspec-core (~> 3.12.0)
|
40
|
+
rspec-expectations (~> 3.12.0)
|
41
|
+
rspec-mocks (~> 3.12.0)
|
42
|
+
rspec-core (3.12.2)
|
43
|
+
rspec-support (~> 3.12.0)
|
44
|
+
rspec-expectations (3.12.3)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.12.0)
|
47
|
+
rspec-mocks (3.12.6)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.12.0)
|
50
|
+
rspec-support (3.12.1)
|
51
|
+
ruby2_keywords (0.0.5)
|
52
|
+
thor (1.3.0)
|
53
|
+
tzinfo (2.0.6)
|
54
|
+
concurrent-ruby (~> 1.0)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
activemodel (~> 7.1.1)
|
61
|
+
appraisal
|
62
|
+
bundler (>= 2)
|
63
|
+
nested_record!
|
64
|
+
rake (~> 13.0)
|
65
|
+
rspec (~> 3.0)
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
2.4.20
|
data/lib/nested_record/base.rb
CHANGED
@@ -143,11 +143,11 @@ class NestedRecord::Base
|
|
143
143
|
subclass ||=
|
144
144
|
begin
|
145
145
|
if type_name.start_with?('::')
|
146
|
-
|
146
|
+
NestedRecord.constantize(type_name)
|
147
147
|
elsif subtypes_store_full?
|
148
|
-
|
148
|
+
NestedRecord.constantize(type_name)
|
149
149
|
elsif subtypes_namespace
|
150
|
-
|
150
|
+
NestedRecord.safe_constantize("#{subtypes_namespace}::#{type_name}") || NestedRecord.constantize(type_name)
|
151
151
|
else
|
152
152
|
NestedRecord.lookup_const(self, type_name)
|
153
153
|
end
|
@@ -1,18 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module NestedRecord
|
4
|
-
#
|
4
|
+
# TODO: Remove this when we drop support for Rails < 7.0
|
5
|
+
if ActiveSupport::VERSION::MAJOR < 7
|
6
|
+
def self.constantize(type_name)
|
7
|
+
ActiveSupport::Dependencies.constantize(type_name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.safe_constantize(type_name)
|
11
|
+
ActiveSupport::Dependencies.safe_constantize(type_name)
|
12
|
+
end
|
13
|
+
else
|
14
|
+
def self.constantize(type_name)
|
15
|
+
type_name.constantize
|
16
|
+
end
|
5
17
|
|
18
|
+
def self.safe_constantize(type_name)
|
19
|
+
type_name.safe_constantize
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Derived from Rails source: https://github.com/rails/rails/blob/98a57aa5f610bc66af31af409c72173cdeeb3c9e/activerecord/lib/active_record/inheritance.rb#L181-L207
|
6
24
|
def self.lookup_const(owner, type_name)
|
7
25
|
if type_name.start_with?('::')
|
8
|
-
|
26
|
+
NestedRecord.constantize(type_name)
|
9
27
|
else
|
10
28
|
candidates = []
|
11
29
|
owner.name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" }
|
12
30
|
candidates << type_name
|
13
31
|
|
14
32
|
candidates.each do |candidate|
|
15
|
-
constant =
|
33
|
+
constant = NestedRecord.safe_constantize(candidate)
|
16
34
|
return constant if candidate == constant.to_s
|
17
35
|
end
|
18
36
|
|
data/lib/nested_record.rb
CHANGED
data/nested_record.gemspec
CHANGED
data/spec/support/model.rb
CHANGED
@@ -64,9 +64,19 @@ module TestModel
|
|
64
64
|
module Erase
|
65
65
|
def erase_test_consts
|
66
66
|
Array(@test_consts).reverse_each do |klass|
|
67
|
-
|
67
|
+
remove_constant(klass.name)
|
68
|
+
end
|
69
|
+
ActiveSupport::Dependencies.clear unless zeitwerk?
|
70
|
+
end
|
71
|
+
|
72
|
+
def remove_constant(klass_name)
|
73
|
+
if ActiveSupport::Dependencies.respond_to?(:remove_constant)
|
74
|
+
ActiveSupport::Dependencies.remove_constant(klass_name)
|
75
|
+
else
|
76
|
+
base, _, object = klass_name.to_s.rpartition('::')
|
77
|
+
base = base.empty? ? Object : NestedRecord.constantize(base)
|
78
|
+
base.send :remove_const, object
|
68
79
|
end
|
69
|
-
ActiveSupport::Dependencies.clear
|
70
80
|
end
|
71
81
|
|
72
82
|
def test_const_dig_name!(name)
|
@@ -85,5 +95,9 @@ module TestModel
|
|
85
95
|
end
|
86
96
|
[namespace, name]
|
87
97
|
end
|
98
|
+
|
99
|
+
def zeitwerk?
|
100
|
+
ActiveSupport::VERSION::MAJOR >= 7
|
101
|
+
end
|
88
102
|
end
|
89
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nested_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kochnev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,22 +70,22 @@ dependencies:
|
|
70
70
|
name: activemodel
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '5.2'
|
76
76
|
- - "<"
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version: '
|
78
|
+
version: '7.2'
|
79
79
|
type: :runtime
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
|
-
- - "
|
83
|
+
- - ">"
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
85
|
+
version: '5.2'
|
86
86
|
- - "<"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
88
|
+
version: '7.2'
|
89
89
|
description:
|
90
90
|
email:
|
91
91
|
- hashtable@yandex.ru
|
@@ -110,6 +110,10 @@ files:
|
|
110
110
|
- gemfiles/rails_6.0.gemfile.lock
|
111
111
|
- gemfiles/rails_6.1.gemfile
|
112
112
|
- gemfiles/rails_6.1.gemfile.lock
|
113
|
+
- gemfiles/rails_7.0.gemfile
|
114
|
+
- gemfiles/rails_7.0.gemfile.lock
|
115
|
+
- gemfiles/rails_7.1.gemfile
|
116
|
+
- gemfiles/rails_7.1.gemfile.lock
|
113
117
|
- lib/nested_record.rb
|
114
118
|
- lib/nested_record/base.rb
|
115
119
|
- lib/nested_record/collection.rb
|
@@ -157,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
161
|
- !ruby/object:Gem::Version
|
158
162
|
version: '0'
|
159
163
|
requirements: []
|
160
|
-
rubygems_version: 3.
|
164
|
+
rubygems_version: 3.4.20
|
161
165
|
signing_key:
|
162
166
|
specification_version: 4
|
163
167
|
summary: ActiveModel mapper for JSON fields
|