active_data 1.1.7 → 1.2.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 +4 -4
- data/.github/workflows/ci.yml +35 -0
- data/Appraisals +1 -1
- data/CHANGELOG.md +4 -0
- data/gemfiles/rails.5.0.gemfile +15 -0
- data/gemfiles/rails.6.1.gemfile +14 -0
- data/gemfiles/rails.7.0.gemfile +14 -0
- data/lib/active_data/model/representation.rb +17 -6
- data/lib/active_data/model/scopes.rb +35 -7
- data/lib/active_data/model/validations/associated.rb +1 -1
- data/lib/active_data/model/validations/nested.rb +21 -12
- data/lib/active_data/version.rb +1 -1
- data/spec/lib/active_data/model/attributes/localized_spec.rb +1 -1
- data/spec/lib/active_data/model/typecasting_spec.rb +4 -4
- metadata +7 -4
- data/.travis.yml +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80daeb6d630cc5fc243193c917e0b43f19b2fce35a746200551921f3892e1677
|
4
|
+
data.tar.gz: 4fc2d73f4d3a59ce0804fa652ba782ee33997e9be4870b4ee402d67b920a8c45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d8fe25346c0e72ac3600ed8f89266864cf86081d8a0db463e4b856688e7c5cd7a936b76c872f7470a0f942989ecc51bf5e1a0615ea68f74855119910607b139
|
7
|
+
data.tar.gz: c0f31ed6be42bbe6e3d06f82e4d546c04b72b7a527cb628019516531b430273a89eae8c727a4c4edc2010aa3cdd80fa8195953f793296e4726b2d5f666b973ec
|
@@ -0,0 +1,35 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
rspec:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
include:
|
9
|
+
- { ruby: '2.3', rails: '4.2' }
|
10
|
+
- { ruby: '2.4', rails: '5.0' }
|
11
|
+
- { ruby: '2.5', rails: '5.1' }
|
12
|
+
- { ruby: '2.6', rails: '5.2' }
|
13
|
+
- { ruby: '2.7', rails: '6.0' }
|
14
|
+
- { ruby: '3.0', rails: '6.1' }
|
15
|
+
- { ruby: '3.0', rails: '7.0' }
|
16
|
+
runs-on: ubuntu-latest
|
17
|
+
env:
|
18
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails.${{ matrix.rails }}.gemfile
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
- uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby }}
|
24
|
+
bundler-cache: true
|
25
|
+
- run: bundle exec rspec
|
26
|
+
|
27
|
+
rubocop:
|
28
|
+
runs-on: ubuntu-latest
|
29
|
+
steps:
|
30
|
+
- uses: actions/checkout@v2
|
31
|
+
- uses: ruby/setup-ruby@v1
|
32
|
+
with:
|
33
|
+
ruby-version: 3.0
|
34
|
+
bundler-cache: true
|
35
|
+
- run: bundle exec rubocop
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 5.0.0"
|
6
|
+
gem "activemodel", "~> 5.0.0"
|
7
|
+
gem "activerecord", "~> 5.0.0"
|
8
|
+
gem "sqlite3", "~> 1.3.6"
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem "guard"
|
12
|
+
gem "guard-rspec"
|
13
|
+
end
|
14
|
+
|
15
|
+
gemspec path: "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 6.1.0"
|
6
|
+
gem "activemodel", "~> 6.1.0"
|
7
|
+
gem "activerecord", "~> 6.1.0"
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 7.0.0"
|
6
|
+
gem "activemodel", "~> 7.0.0"
|
7
|
+
gem "activerecord", "~> 7.0.0"
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_model/version'
|
1
2
|
require 'active_data/model/attributes/reflections/represents'
|
2
3
|
require 'active_data/model/attributes/represents'
|
3
4
|
|
@@ -67,14 +68,24 @@ module ActiveData
|
|
67
68
|
#
|
68
69
|
def emerge_represented_attributes_errors!
|
69
70
|
self.class.represented_attributes.each do |attribute|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
move_errors(:"#{attribute.reference}.#{attribute.column}", attribute.column)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
if ActiveModel.version >= Gem::Version.new('6.1.0')
|
76
|
+
def move_errors(from, to)
|
77
|
+
errors[from].each do |error_message|
|
78
|
+
errors.add(to, error_message)
|
79
|
+
errors.delete(from)
|
76
80
|
end
|
77
81
|
end
|
82
|
+
else # up to 6.0.x
|
83
|
+
def move_errors(from, to)
|
84
|
+
return unless errors.messages.key?(from) && errors.messages[from].present?
|
85
|
+
|
86
|
+
errors[to].concat(errors.messages[from])
|
87
|
+
errors.delete(from)
|
88
|
+
end
|
78
89
|
end
|
79
90
|
end
|
80
91
|
end
|
@@ -37,16 +37,44 @@ module ActiveData
|
|
37
37
|
super || self.class._scope_model.respond_to?(method)
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
# rubocop:disable Style/MethodMissing
|
41
|
+
# rubocop-0.52.1 doesn't understand that `#respond_to_missing?` is defined above
|
42
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
|
43
|
+
def method_missing(method, *args, **kwargs, &block)
|
44
|
+
with_scope do
|
45
|
+
model = self.class._scope_model
|
46
|
+
if model.respond_to?(method)
|
47
|
+
result = model.public_send(method, *args, **kwargs, &block)
|
48
|
+
result.is_a?(ActiveData::Model::Scopes) ? result : model.scope_class.new(result)
|
49
|
+
else
|
50
|
+
super
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
|
55
|
+
def method_missing(method, *args, **kwargs, &block)
|
56
|
+
with_scope do
|
57
|
+
model = self.class._scope_model
|
58
|
+
if model.respond_to?(method)
|
59
|
+
model.public_send(method, *args, **kwargs, &block)
|
60
|
+
else
|
61
|
+
super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
else # up to 2.6.x
|
66
|
+
def method_missing(method, *args, &block)
|
67
|
+
with_scope do
|
68
|
+
model = self.class._scope_model
|
69
|
+
if model.respond_to?(method)
|
70
|
+
model.public_send(method, *args, &block)
|
71
|
+
else
|
72
|
+
super
|
73
|
+
end
|
47
74
|
end
|
48
75
|
end
|
49
76
|
end
|
77
|
+
# rubocop:enable Style/MethodMissing
|
50
78
|
|
51
79
|
def with_scope
|
52
80
|
previous_scope = self.class._scope_model.current_scope
|
@@ -6,7 +6,7 @@ module ActiveData
|
|
6
6
|
invalid_records = Array.wrap(value).reject do |r|
|
7
7
|
r.respond_to?(:valid?) && r.valid?(record.validation_context)
|
8
8
|
end
|
9
|
-
record.errors.add(attribute, :invalid, options.merge(value: value)) if invalid_records.present?
|
9
|
+
record.errors.add(attribute, :invalid, **options.merge(value: value)) if invalid_records.present?
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_model/version'
|
2
|
+
|
1
3
|
module ActiveData
|
2
4
|
module Model
|
3
5
|
module Validations
|
@@ -5,19 +7,26 @@ module ActiveData
|
|
5
7
|
def self.validate_nested(record, name, value)
|
6
8
|
if value.is_a?(Enumerable)
|
7
9
|
value.each.with_index do |object, i|
|
8
|
-
if yield
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
import_errors(object.errors, record.errors, "#{name}.#{i}") if yield object
|
11
|
+
end
|
12
|
+
elsif value
|
13
|
+
import_errors(value.errors, record.errors, name.to_s) if yield value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if ActiveModel.version >= Gem::Version.new('6.1.0')
|
18
|
+
def self.import_errors(from, to, prefix)
|
19
|
+
from.each do |error|
|
20
|
+
key = "#{prefix}.#{error.attribute}"
|
21
|
+
to.import(error, attribute: key) unless to.added?(key, error.type, error.options)
|
15
22
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
end
|
24
|
+
else # up to 6.0.x
|
25
|
+
def self.import_errors(from, to, prefix)
|
26
|
+
from.each do |key, message|
|
27
|
+
key = "#{prefix}.#{key}"
|
28
|
+
to[key] << message
|
29
|
+
to[key].uniq!
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
data/lib/active_data/version.rb
CHANGED
@@ -93,7 +93,7 @@ describe ActiveData::Model::Attributes::Localized do
|
|
93
93
|
before do
|
94
94
|
require 'i18n/backend/fallbacks'
|
95
95
|
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
96
|
-
I18n.fallbacks
|
96
|
+
I18n.fallbacks[:en] = [:ru]
|
97
97
|
end
|
98
98
|
after { I18n.fallbacks = false }
|
99
99
|
its(:name) { should == 'Привет' }
|
@@ -66,11 +66,11 @@ describe ActiveData::Model::Attributes do
|
|
66
66
|
|
67
67
|
specify { expect(model.new(column: 'hello').column).to be_nil }
|
68
68
|
specify { expect(model.new(column: '123hello').column).to be_nil }
|
69
|
-
specify { expect(model.new(column: '123').column).to eq(BigDecimal
|
69
|
+
specify { expect(model.new(column: '123').column).to eq(BigDecimal('123.0')) }
|
70
70
|
specify { expect(model.new(column: '123.').column).to be_nil }
|
71
|
-
specify { expect(model.new(column: '123.5').column).to eq(BigDecimal
|
72
|
-
specify { expect(model.new(column: 123).column).to eq(BigDecimal
|
73
|
-
specify { expect(model.new(column: 123.5).column).to eq(BigDecimal
|
71
|
+
specify { expect(model.new(column: '123.5').column).to eq(BigDecimal('123.5')) }
|
72
|
+
specify { expect(model.new(column: 123).column).to eq(BigDecimal('123.0')) }
|
73
|
+
specify { expect(model.new(column: 123.5).column).to eq(BigDecimal('123.5')) }
|
74
74
|
specify { expect(model.new(column: nil).column).to be_nil }
|
75
75
|
specify { expect(model.new(column: [123.5]).column).to be_nil }
|
76
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pyromaniac
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -200,11 +200,11 @@ extensions: []
|
|
200
200
|
extra_rdoc_files: []
|
201
201
|
files:
|
202
202
|
- ".codeclimate.yml"
|
203
|
+
- ".github/workflows/ci.yml"
|
203
204
|
- ".gitignore"
|
204
205
|
- ".rspec"
|
205
206
|
- ".rubocop.yml"
|
206
207
|
- ".rubocop_todo.yml"
|
207
|
-
- ".travis.yml"
|
208
208
|
- Appraisals
|
209
209
|
- CHANGELOG.md
|
210
210
|
- Gemfile
|
@@ -214,9 +214,12 @@ files:
|
|
214
214
|
- Rakefile
|
215
215
|
- active_data.gemspec
|
216
216
|
- gemfiles/rails.4.2.gemfile
|
217
|
+
- gemfiles/rails.5.0.gemfile
|
217
218
|
- gemfiles/rails.5.1.gemfile
|
218
219
|
- gemfiles/rails.5.2.gemfile
|
219
220
|
- gemfiles/rails.6.0.gemfile
|
221
|
+
- gemfiles/rails.6.1.gemfile
|
222
|
+
- gemfiles/rails.7.0.gemfile
|
220
223
|
- lib/active_data.rb
|
221
224
|
- lib/active_data/active_record/associations.rb
|
222
225
|
- lib/active_data/active_record/nested_attributes.rb
|
@@ -345,7 +348,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
345
348
|
- !ruby/object:Gem::Version
|
346
349
|
version: '0'
|
347
350
|
requirements: []
|
348
|
-
rubygems_version: 3.1.
|
351
|
+
rubygems_version: 3.1.4
|
349
352
|
signing_key:
|
350
353
|
specification_version: 4
|
351
354
|
summary: Working with hashes in AR style
|
data/.travis.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
|
3
|
-
matrix:
|
4
|
-
include:
|
5
|
-
- rvm: 2.3.8
|
6
|
-
gemfile: gemfiles/rails.4.2.gemfile
|
7
|
-
- rvm: 2.4.7
|
8
|
-
gemfile: gemfiles/rails.5.1.gemfile
|
9
|
-
- rvm: 2.5.6
|
10
|
-
gemfile: gemfiles/rails.5.2.gemfile
|
11
|
-
- rvm: 2.6.4
|
12
|
-
gemfile: gemfiles/rails.6.0.gemfile
|
13
|
-
|
14
|
-
script:
|
15
|
-
- bundle exec rspec
|
16
|
-
- bundle exec rubocop
|