active_type 1.4.0 → 1.7.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/test.yml +175 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile.3.2.mysql2 +1 -1
- data/Gemfile.3.2.mysql2.lock +11 -5
- data/Gemfile.3.2.sqlite3.lock +3 -3
- data/Gemfile.4.2.mysql2 +1 -1
- data/Gemfile.4.2.mysql2.lock +5 -5
- data/Gemfile.4.2.pg.lock +3 -3
- data/Gemfile.4.2.sqlite3.lock +3 -3
- data/Gemfile.5.2.mysql2.lock +27 -27
- data/Gemfile.5.2.pg.lock +27 -27
- data/Gemfile.5.2.sqlite3.lock +27 -27
- data/{Gemfile.6.0.pg → Gemfile.6.0.sqlite3} +1 -1
- data/Gemfile.6.0.sqlite3.lock +59 -0
- data/Gemfile.6.1.pg +9 -0
- data/Gemfile.6.1.pg.lock +58 -0
- data/Gemfile.6.1.sqlite3 +9 -0
- data/Gemfile.6.1.sqlite3.lock +58 -0
- data/README.md +20 -6
- data/Rakefile +1 -1
- data/lib/active_type/change_association.rb +2 -2
- data/lib/active_type/nested_attributes/association.rb +19 -7
- data/lib/active_type/record_extension/inheritance.rb +24 -6
- data/lib/active_type/version.rb +1 -1
- data/lib/active_type/virtual_attributes.rb +53 -11
- metadata +10 -6
- data/.travis.yml +0 -72
- data/Gemfile.6.0.pg.lock +0 -59
@@ -15,9 +15,9 @@ module ActiveType
|
|
15
15
|
original_options = existing_association.options
|
16
16
|
if ActiveRecord::VERSION::MAJOR > 3
|
17
17
|
new_scope ||= existing_association.scope
|
18
|
-
public_send(existing_association.macro, association_name, new_scope, original_options.merge(new_options))
|
18
|
+
public_send(existing_association.macro, association_name, new_scope, **original_options.merge(new_options))
|
19
19
|
else
|
20
|
-
public_send(existing_association.macro, association_name, original_options.merge(new_options))
|
20
|
+
public_send(existing_association.macro, association_name, **original_options.merge(new_options))
|
21
21
|
end
|
22
22
|
else
|
23
23
|
raise ArgumentError, "unrecognized association `#{association_name}`"
|
@@ -42,13 +42,7 @@ module ActiveType
|
|
42
42
|
|
43
43
|
def validate(parent)
|
44
44
|
changed_children(parent).each_with_index do |child, index|
|
45
|
-
unless child.valid?
|
46
|
-
child.errors.each do |attribute, message|
|
47
|
-
attribute = @index_errors ? "#{@target_name}[#{index}].#{attribute}" : "#{@target_name}.#{attribute}"
|
48
|
-
parent.errors[attribute] << message
|
49
|
-
parent.errors[attribute].uniq!
|
50
|
-
end
|
51
|
-
end
|
45
|
+
add_errors_to_parent(parent, child, index) unless child.valid?
|
52
46
|
end
|
53
47
|
end
|
54
48
|
|
@@ -131,6 +125,24 @@ module ActiveType
|
|
131
125
|
[:build_scope, :find_scope, :scope, :allow_destroy, :reject_if]
|
132
126
|
end
|
133
127
|
|
128
|
+
def add_errors_to_parent(parent, child, index)
|
129
|
+
if ActiveRecord::VERSION::MAJOR >= 6 && ActiveRecord::VERSION::MINOR >= 1
|
130
|
+
child.errors.each do |error|
|
131
|
+
attribute = translate_error_attribute(error.attribute, index)
|
132
|
+
parent.errors.add(attribute, error.message)
|
133
|
+
end
|
134
|
+
else
|
135
|
+
child.errors.each do |attribute, message|
|
136
|
+
attribute = translate_error_attribute(attribute, index)
|
137
|
+
parent.errors.add(attribute, message)
|
138
|
+
parent.errors[attribute].uniq!
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def translate_error_attribute(attribute, index)
|
144
|
+
@index_errors ? "#{@target_name}[#{index}].#{attribute}" : "#{@target_name}.#{attribute}"
|
145
|
+
end
|
134
146
|
end
|
135
147
|
|
136
148
|
end
|
@@ -19,7 +19,7 @@ module ActiveType
|
|
19
19
|
options = options.merge(foreign_key: extended_record_base_class.name.foreign_key)
|
20
20
|
end
|
21
21
|
if ActiveRecord::VERSION::MAJOR > 3
|
22
|
-
[
|
22
|
+
[options, scope]
|
23
23
|
else
|
24
24
|
[options]
|
25
25
|
end
|
@@ -31,7 +31,7 @@ module ActiveType
|
|
31
31
|
@_model_name ||= begin
|
32
32
|
if name
|
33
33
|
# Namespace detection copied from ActiveModel::Naming
|
34
|
-
namespace =
|
34
|
+
namespace = module_ancestors.detect do |n|
|
35
35
|
n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
|
36
36
|
end
|
37
37
|
# We create a Name object, with the parent class name, but self as the @klass reference
|
@@ -48,6 +48,14 @@ module ActiveType
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
def module_ancestors
|
52
|
+
if extended_record_base_class.respond_to?(:module_parents)
|
53
|
+
extended_record_base_class.module_parents
|
54
|
+
else
|
55
|
+
extended_record_base_class.parents
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
51
59
|
def sti_name
|
52
60
|
extended_record_base_class.sti_name
|
53
61
|
end
|
@@ -56,12 +64,22 @@ module ActiveType
|
|
56
64
|
extended_record_base_class.descends_from_active_record?
|
57
65
|
end
|
58
66
|
|
59
|
-
def has_many(name, *args, &extension)
|
60
|
-
|
67
|
+
def has_many(name, scope=nil, *args, &extension)
|
68
|
+
new_args, new_scope = Inheritance.add_foreign_key_option(extended_record_base_class, scope, *args)
|
69
|
+
if ActiveRecord::VERSION::MAJOR <= 3 || new_scope.nil?
|
70
|
+
super(name, **new_args, &extension)
|
71
|
+
else
|
72
|
+
super(name, new_scope, **new_args, &extension)
|
73
|
+
end
|
61
74
|
end
|
62
75
|
|
63
|
-
def has_one(name, *args, &extension)
|
64
|
-
|
76
|
+
def has_one(name, scope=nil, *args, &extension)
|
77
|
+
new_args, new_scope = Inheritance.add_foreign_key_option(extended_record_base_class, scope, *args)
|
78
|
+
if ActiveRecord::VERSION::MAJOR <= 3 || new_scope.nil?
|
79
|
+
super(name, **new_args, &extension)
|
80
|
+
else
|
81
|
+
super(name, new_scope, **new_args, &extension)
|
82
|
+
end
|
65
83
|
end
|
66
84
|
|
67
85
|
private
|
data/lib/active_type/version.rb
CHANGED
@@ -8,6 +8,23 @@ module ActiveType
|
|
8
8
|
|
9
9
|
module VirtualAttributes
|
10
10
|
|
11
|
+
module Serialization
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
def init_with(coder)
|
15
|
+
if coder['virtual_attributes'].present?
|
16
|
+
@virtual_attributes = coder['virtual_attributes']
|
17
|
+
end
|
18
|
+
super(coder)
|
19
|
+
end
|
20
|
+
|
21
|
+
def encode_with(coder)
|
22
|
+
coder['virtual_attributes'] = @virtual_attributes
|
23
|
+
coder['active_type_yaml_version'] = 1
|
24
|
+
super(coder)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
11
28
|
class VirtualColumn
|
12
29
|
|
13
30
|
def initialize(name, type_caster, options)
|
@@ -110,10 +127,10 @@ module ActiveType
|
|
110
127
|
result
|
111
128
|
end
|
112
129
|
|
113
|
-
|
114
130
|
extend ActiveSupport::Concern
|
115
131
|
|
116
132
|
included do
|
133
|
+
include ActiveType::VirtualAttributes::Serialization
|
117
134
|
class_attribute :virtual_columns_hash
|
118
135
|
self.virtual_columns_hash = {}
|
119
136
|
|
@@ -144,28 +161,53 @@ module ActiveType
|
|
144
161
|
@virtual_attributes_cache ||= {}
|
145
162
|
end
|
146
163
|
|
147
|
-
def
|
164
|
+
def read_existing_virtual_attribute(name, &block_when_not_virtual)
|
148
165
|
if self.singleton_class._has_virtual_column?(name)
|
149
166
|
read_virtual_attribute(name)
|
150
167
|
else
|
151
|
-
|
168
|
+
yield
|
152
169
|
end
|
153
170
|
end
|
154
171
|
|
155
|
-
|
156
|
-
def _read_attribute(name)
|
172
|
+
def write_existing_virtual_attribute(name, value, &block_when_not_virtual)
|
157
173
|
if self.singleton_class._has_virtual_column?(name)
|
158
|
-
|
174
|
+
write_virtual_attribute(name, value)
|
159
175
|
else
|
160
|
-
|
176
|
+
yield
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def [](name)
|
181
|
+
read_existing_virtual_attribute(name) { super }
|
182
|
+
end
|
183
|
+
|
184
|
+
if ActiveRecord::VERSION::STRING >= '4.2.0'
|
185
|
+
def _read_attribute(name)
|
186
|
+
read_existing_virtual_attribute(name) { super }
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
if ActiveRecord::VERSION::STRING < '4.2.0' || ActiveRecord::VERSION::STRING >= '6.1.0'
|
191
|
+
# in 6.1, read_attribute does not call _read_attribute
|
192
|
+
def read_attribute(name)
|
193
|
+
read_existing_virtual_attribute(name) { super }
|
161
194
|
end
|
162
195
|
end
|
163
196
|
|
164
197
|
def []=(name, value)
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
198
|
+
write_existing_virtual_attribute(name, value) { super }
|
199
|
+
end
|
200
|
+
|
201
|
+
if ActiveRecord::VERSION::STRING >= '5.2.0'
|
202
|
+
def _write_attribute(name, value)
|
203
|
+
write_existing_virtual_attribute(name, value) { super }
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
if ActiveRecord::VERSION::STRING < '5.2.0' || ActiveRecord::VERSION::STRING >= '6.1.0'
|
208
|
+
# in 6.1, write_attribute does not call _write_attribute
|
209
|
+
def write_attribute(name, value)
|
210
|
+
write_existing_virtual_attribute(name, value) { super }
|
169
211
|
end
|
170
212
|
end
|
171
213
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_type
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Kraze
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -59,10 +59,10 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".github/workflows/test.yml"
|
62
63
|
- ".gitignore"
|
63
64
|
- ".rspec"
|
64
65
|
- ".ruby-version"
|
65
|
-
- ".travis.yml"
|
66
66
|
- CHANGELOG.md
|
67
67
|
- Gemfile
|
68
68
|
- Gemfile.3.2.mysql2
|
@@ -81,8 +81,12 @@ files:
|
|
81
81
|
- Gemfile.5.2.pg.lock
|
82
82
|
- Gemfile.5.2.sqlite3
|
83
83
|
- Gemfile.5.2.sqlite3.lock
|
84
|
-
- Gemfile.6.0.
|
85
|
-
- Gemfile.6.0.
|
84
|
+
- Gemfile.6.0.sqlite3
|
85
|
+
- Gemfile.6.0.sqlite3.lock
|
86
|
+
- Gemfile.6.1.pg
|
87
|
+
- Gemfile.6.1.pg.lock
|
88
|
+
- Gemfile.6.1.sqlite3
|
89
|
+
- Gemfile.6.1.sqlite3.lock
|
86
90
|
- Gemfile.lock
|
87
91
|
- LICENSE
|
88
92
|
- README.md
|
@@ -123,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
127
|
- !ruby/object:Gem::Version
|
124
128
|
version: '0'
|
125
129
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
130
|
+
rubygems_version: 3.1.4
|
127
131
|
signing_key:
|
128
132
|
specification_version: 4
|
129
133
|
summary: Make any Ruby object quack like ActiveRecord
|
data/.travis.yml
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
dist: trusty
|
3
|
-
services:
|
4
|
-
- postgresql
|
5
|
-
rvm:
|
6
|
-
- "2.3.8"
|
7
|
-
- "2.4.6"
|
8
|
-
- "2.5.5"
|
9
|
-
- "2.6.3"
|
10
|
-
gemfile:
|
11
|
-
- Gemfile.3.2.mysql2
|
12
|
-
- Gemfile.3.2.sqlite3
|
13
|
-
- Gemfile.4.2.mysql2
|
14
|
-
- Gemfile.4.2.pg
|
15
|
-
- Gemfile.4.2.sqlite3
|
16
|
-
- Gemfile.5.2.mysql2
|
17
|
-
- Gemfile.5.2.sqlite3
|
18
|
-
- Gemfile.5.2.pg
|
19
|
-
- Gemfile.6.0.pg
|
20
|
-
before_script:
|
21
|
-
- psql -c 'create database active_type_test;' -U postgres
|
22
|
-
- mysql -e 'create database IF NOT EXISTS active_type_test;'
|
23
|
-
script: bundle exec rake spec
|
24
|
-
sudo: false
|
25
|
-
cache: bundler
|
26
|
-
matrix:
|
27
|
-
exclude:
|
28
|
-
- rvm: "2.3.8"
|
29
|
-
gemfile: Gemfile.6.0.pg
|
30
|
-
- rvm: "2.4.6"
|
31
|
-
gemfile: Gemfile.3.2.mysql2
|
32
|
-
- rvm: "2.4.6"
|
33
|
-
gemfile: Gemfile.3.2.sqlite3
|
34
|
-
- rvm: "2.4.6"
|
35
|
-
gemfile: Gemfile.4.2.mysql2
|
36
|
-
- rvm: "2.4.6"
|
37
|
-
gemfile: Gemfile.4.2.pg
|
38
|
-
- rvm: "2.4.6"
|
39
|
-
gemfile: Gemfile.5.2.mysql2
|
40
|
-
- rvm: "2.4.6"
|
41
|
-
gemfile: Gemfile.5.2.pg
|
42
|
-
- rvm: "2.4.6"
|
43
|
-
gemfile: Gemfile.6.0.pg
|
44
|
-
- rvm: "2.5.5"
|
45
|
-
gemfile: Gemfile.3.2.mysql2
|
46
|
-
- rvm: "2.5.5"
|
47
|
-
gemfile: Gemfile.3.2.sqlite3
|
48
|
-
- rvm: "2.5.5"
|
49
|
-
gemfile: Gemfile.4.2.mysql2
|
50
|
-
- rvm: "2.5.5"
|
51
|
-
gemfile: Gemfile.4.2.pg
|
52
|
-
- rvm: "2.5.5"
|
53
|
-
gemfile: Gemfile.4.2.sqlite3
|
54
|
-
- rvm: "2.5.5"
|
55
|
-
gemfile: Gemfile.5.2.mysql2
|
56
|
-
- rvm: "2.5.5"
|
57
|
-
gemfile: Gemfile.5.2.pg
|
58
|
-
- rvm: "2.6.3"
|
59
|
-
gemfile: Gemfile.3.2.mysql2
|
60
|
-
- rvm: "2.6.3"
|
61
|
-
gemfile: Gemfile.3.2.sqlite3
|
62
|
-
- rvm: "2.6.3"
|
63
|
-
gemfile: Gemfile.4.2.mysql2
|
64
|
-
- rvm: "2.6.3"
|
65
|
-
gemfile: Gemfile.4.2.pg
|
66
|
-
- rvm: "2.6.3"
|
67
|
-
gemfile: Gemfile.4.2.sqlite3
|
68
|
-
install:
|
69
|
-
- gem install bundler:2.0.2
|
70
|
-
- bundle install --no-deployment --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
|
71
|
-
addons:
|
72
|
-
postgresql: 9.3
|
data/Gemfile.6.0.pg.lock
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
active_type (1.3.2)
|
5
|
-
activerecord (>= 3.2)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activemodel (6.0.0)
|
11
|
-
activesupport (= 6.0.0)
|
12
|
-
activerecord (6.0.0)
|
13
|
-
activemodel (= 6.0.0)
|
14
|
-
activesupport (= 6.0.0)
|
15
|
-
activesupport (6.0.0)
|
16
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
-
i18n (>= 0.7, < 2)
|
18
|
-
minitest (~> 5.1)
|
19
|
-
tzinfo (~> 1.1)
|
20
|
-
zeitwerk (~> 2.1, >= 2.1.8)
|
21
|
-
concurrent-ruby (1.1.5)
|
22
|
-
diff-lcs (1.3)
|
23
|
-
gemika (0.3.4)
|
24
|
-
i18n (1.6.0)
|
25
|
-
concurrent-ruby (~> 1.0)
|
26
|
-
minitest (5.11.3)
|
27
|
-
pg (1.1.4)
|
28
|
-
rake (12.3.2)
|
29
|
-
rspec (3.8.0)
|
30
|
-
rspec-core (~> 3.8.0)
|
31
|
-
rspec-expectations (~> 3.8.0)
|
32
|
-
rspec-mocks (~> 3.8.0)
|
33
|
-
rspec-core (3.8.0)
|
34
|
-
rspec-support (~> 3.8.0)
|
35
|
-
rspec-expectations (3.8.2)
|
36
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.8.0)
|
38
|
-
rspec-mocks (3.8.0)
|
39
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.8.0)
|
41
|
-
rspec-support (3.8.0)
|
42
|
-
thread_safe (0.3.6)
|
43
|
-
tzinfo (1.2.5)
|
44
|
-
thread_safe (~> 0.1)
|
45
|
-
zeitwerk (2.1.9)
|
46
|
-
|
47
|
-
PLATFORMS
|
48
|
-
ruby
|
49
|
-
|
50
|
-
DEPENDENCIES
|
51
|
-
active_type!
|
52
|
-
activerecord (~> 6.0.0)
|
53
|
-
gemika
|
54
|
-
pg
|
55
|
-
rake
|
56
|
-
rspec (~> 3.4)
|
57
|
-
|
58
|
-
BUNDLED WITH
|
59
|
-
2.0.2
|