active_type 1.2.1 → 1.4.1
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/.travis.yml +37 -16
- data/CHANGELOG.md +67 -1
- data/Gemfile.3.2.mysql2.lock +2 -2
- data/Gemfile.3.2.sqlite3.lock +2 -2
- data/Gemfile.4.2.mysql2.lock +2 -2
- data/Gemfile.4.2.pg.lock +2 -2
- data/Gemfile.4.2.sqlite3.lock +2 -2
- data/Gemfile.5.2.mysql2.lock +2 -2
- data/Gemfile.5.2.pg.lock +2 -2
- data/Gemfile.5.2.sqlite3.lock +2 -2
- data/Gemfile.6.0.pg +1 -1
- data/Gemfile.6.0.pg.lock +11 -11
- data/lib/active_type/nested_attributes/nests_one_association.rb +5 -2
- data/lib/active_type/record_extension/inheritance.rb +64 -4
- data/lib/active_type/version.rb +1 -1
- data/lib/active_type/virtual_attributes.rb +2 -0
- metadata +3 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 70a593b09da1c5389129939864d40d6ee562d2bf4b7a3bee41bbf749ba81efff
|
|
4
|
+
data.tar.gz: e8aa031eb6aac62a71556a85c23c55ffa2ee5efa52067226306faca924c7d240
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d287c42812f6afa854f608f52202c1ed6c38cd63aa6cbd7813abbad13c881e8ac333c3f5ce99503bb6c38221c19d0f858307174d37fdc84b2f74fc1b8a61fd1
|
|
7
|
+
data.tar.gz: a966aa55504b560c99782561854487465dc7f46715b5e6deb1eb2a13fa4f016a83147b9306679936147759c2592b83aaae273f809d6f5f3ff3bca6450b49a5dd
|
data/.travis.yml
CHANGED
|
@@ -4,8 +4,9 @@ services:
|
|
|
4
4
|
- postgresql
|
|
5
5
|
rvm:
|
|
6
6
|
- "2.3.8"
|
|
7
|
-
- "2.4.
|
|
8
|
-
- "2.5.
|
|
7
|
+
- "2.4.6"
|
|
8
|
+
- "2.5.5"
|
|
9
|
+
- "2.6.3"
|
|
9
10
|
gemfile:
|
|
10
11
|
- Gemfile.3.2.mysql2
|
|
11
12
|
- Gemfile.3.2.sqlite3
|
|
@@ -22,30 +23,50 @@ before_script:
|
|
|
22
23
|
script: bundle exec rake spec
|
|
23
24
|
sudo: false
|
|
24
25
|
cache: bundler
|
|
25
|
-
notifications:
|
|
26
|
-
email:
|
|
27
|
-
- fail@makandra.de
|
|
28
26
|
matrix:
|
|
29
27
|
exclude:
|
|
30
|
-
- rvm: "2.
|
|
28
|
+
- rvm: "2.3.8"
|
|
29
|
+
gemfile: Gemfile.6.0.pg
|
|
30
|
+
- rvm: "2.4.6"
|
|
31
31
|
gemfile: Gemfile.3.2.mysql2
|
|
32
|
-
- rvm: "2.4.
|
|
32
|
+
- rvm: "2.4.6"
|
|
33
33
|
gemfile: Gemfile.3.2.sqlite3
|
|
34
|
-
- rvm: "2.
|
|
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"
|
|
35
45
|
gemfile: Gemfile.3.2.mysql2
|
|
36
|
-
- rvm: "2.5.
|
|
46
|
+
- rvm: "2.5.5"
|
|
37
47
|
gemfile: Gemfile.3.2.sqlite3
|
|
38
|
-
- rvm: "2.5.
|
|
48
|
+
- rvm: "2.5.5"
|
|
39
49
|
gemfile: Gemfile.4.2.mysql2
|
|
40
|
-
- rvm: "2.5.
|
|
50
|
+
- rvm: "2.5.5"
|
|
41
51
|
gemfile: Gemfile.4.2.pg
|
|
42
|
-
- rvm: "2.5.
|
|
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"
|
|
43
67
|
gemfile: Gemfile.4.2.sqlite3
|
|
44
|
-
- rvm: "2.3.8"
|
|
45
|
-
gemfile: Gemfile.6.0.pg
|
|
46
|
-
- rvm: "2.4.5"
|
|
47
|
-
gemfile: Gemfile.6.0.pg
|
|
48
68
|
install:
|
|
69
|
+
- gem install bundler:2.0.2
|
|
49
70
|
- bundle install --no-deployment --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
|
|
50
71
|
addons:
|
|
51
72
|
postgresql: 9.3
|
data/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
-
## Unreleased
|
|
5
|
+
## Unreleased changes
|
|
6
|
+
|
|
7
|
+
## 1.4.0 (2020-07-27)
|
|
8
|
+
|
|
9
|
+
* Extended records now use their own I18n namespace when looking up translations for models or attributes.
|
|
10
|
+
If the extended record's namespace does not contain a translation, the lookup will fall back to the
|
|
11
|
+
base record's namespace.
|
|
12
|
+
|
|
13
|
+
For instance, given the following class hierarchy:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
class User < ActiveRecord::Base
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class User::Form < ActiveType::Record[User]
|
|
20
|
+
end
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The call `ExtendedParent.human_attribute_name(:foo)` would first look up the key in
|
|
24
|
+
`activerecord.attributes.user/form` first, then falls back to `activerecord.attributes.user`.
|
|
25
|
+
|
|
26
|
+
Thank you @fsateler!
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## 1.3.2 (2020-06-16)
|
|
30
|
+
|
|
31
|
+
* Fixed: `nests_one` association record building used empty hash instead of passed in attributes. Credit to @chriscz.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## 1.3.1 (2020-03-31)
|
|
35
|
+
|
|
36
|
+
* Fixed: Avoid #change_association breaking for polymorphic associations. Thanks to @lucthev.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## 1.3.0 (2019-09-26)
|
|
40
|
+
|
|
41
|
+
* Fixed: Do not override Rails internal methods when definining an attribute called `:attribute`.
|
|
42
|
+
* Fixed: Fix .find for extended records, when a record had a `#type` column that was not used for
|
|
43
|
+
single table inheritance. Thanks to @fsateler.
|
|
44
|
+
* Changed: When extending a single table inheritance base class, `.find` no longer crashes, but
|
|
45
|
+
returns records derived from the extended class.
|
|
46
|
+
|
|
47
|
+
This means, that given the following class hierarchy:
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
class Parent < ActiveRecord::Base
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class ExtendedParent < ActiveType::Record[Parent]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class Child < Parent
|
|
57
|
+
end
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
querying
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
ExtendedParent.all
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
will no longer crash, but always return records of type `ExtendedParent` (*even if they
|
|
67
|
+
would normally of type `Child`*). You should probably avoid this weird situation and not
|
|
68
|
+
extend STI Parent classes.
|
|
69
|
+
|
|
70
|
+
Thanks to @fsateler.
|
|
71
|
+
|
|
6
72
|
|
|
7
73
|
## 1.2.1 (2019-07-03)
|
|
8
74
|
* Fixed: Eager loading in Rails 6 no longer crashes trying to load `ActiveType::Object`s.
|
data/Gemfile.3.2.mysql2.lock
CHANGED
data/Gemfile.3.2.sqlite3.lock
CHANGED
data/Gemfile.4.2.mysql2.lock
CHANGED
data/Gemfile.4.2.pg.lock
CHANGED
data/Gemfile.4.2.sqlite3.lock
CHANGED
data/Gemfile.5.2.mysql2.lock
CHANGED
data/Gemfile.5.2.pg.lock
CHANGED
data/Gemfile.5.2.sqlite3.lock
CHANGED
data/Gemfile.6.0.pg
CHANGED
data/Gemfile.6.0.pg.lock
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
active_type (1.2
|
|
4
|
+
active_type (1.3.2)
|
|
5
5
|
activerecord (>= 3.2)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
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
|
|
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
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
17
17
|
i18n (>= 0.7, < 2)
|
|
18
18
|
minitest (~> 5.1)
|
|
19
19
|
tzinfo (~> 1.1)
|
|
20
|
-
zeitwerk (~> 1
|
|
20
|
+
zeitwerk (~> 2.1, >= 2.1.8)
|
|
21
21
|
concurrent-ruby (1.1.5)
|
|
22
22
|
diff-lcs (1.3)
|
|
23
23
|
gemika (0.3.4)
|
|
@@ -42,18 +42,18 @@ GEM
|
|
|
42
42
|
thread_safe (0.3.6)
|
|
43
43
|
tzinfo (1.2.5)
|
|
44
44
|
thread_safe (~> 0.1)
|
|
45
|
-
zeitwerk (1.
|
|
45
|
+
zeitwerk (2.1.9)
|
|
46
46
|
|
|
47
47
|
PLATFORMS
|
|
48
48
|
ruby
|
|
49
49
|
|
|
50
50
|
DEPENDENCIES
|
|
51
51
|
active_type!
|
|
52
|
-
activerecord (~> 6.0.
|
|
52
|
+
activerecord (~> 6.0.0)
|
|
53
53
|
gemika
|
|
54
54
|
pg
|
|
55
55
|
rake
|
|
56
56
|
rspec (~> 3.4)
|
|
57
57
|
|
|
58
58
|
BUNDLED WITH
|
|
59
|
-
|
|
59
|
+
2.0.2
|
|
@@ -30,8 +30,11 @@ module ActiveType
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
elsif !destroy
|
|
33
|
-
assigned_child
|
|
34
|
-
|
|
33
|
+
if assigned_child
|
|
34
|
+
assigned_child.attributes = attributes
|
|
35
|
+
else
|
|
36
|
+
add_child(parent, build_child(parent, attributes))
|
|
37
|
+
end
|
|
35
38
|
end
|
|
36
39
|
end
|
|
37
40
|
|
|
@@ -15,7 +15,7 @@ module ActiveType
|
|
|
15
15
|
options = scope
|
|
16
16
|
scope = nil
|
|
17
17
|
end
|
|
18
|
-
unless options[:foreign_key]
|
|
18
|
+
unless options[:foreign_key] || options[:as]
|
|
19
19
|
options = options.merge(foreign_key: extended_record_base_class.name.foreign_key)
|
|
20
20
|
end
|
|
21
21
|
if ActiveRecord::VERSION::MAJOR > 3
|
|
@@ -28,13 +28,42 @@ module ActiveType
|
|
|
28
28
|
module ClassMethods
|
|
29
29
|
|
|
30
30
|
def model_name
|
|
31
|
-
|
|
31
|
+
@_model_name ||= begin
|
|
32
|
+
if name
|
|
33
|
+
# Namespace detection copied from ActiveModel::Naming
|
|
34
|
+
namespace = module_ancestors.detect do |n|
|
|
35
|
+
n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
|
|
36
|
+
end
|
|
37
|
+
# We create a Name object, with the parent class name, but self as the @klass reference
|
|
38
|
+
# This way lookup_ancestors is invoked on the right class instead of the extended_record_base_class
|
|
39
|
+
dup_model_name = ActiveModel::Name.new(self, namespace, extended_record_base_class.name)
|
|
40
|
+
key = name.underscore
|
|
41
|
+
# We fake the `i18n_key` to lookup on the derived class key
|
|
42
|
+
# We keep the others the same to preserve parameter and route names
|
|
43
|
+
dup_model_name.define_singleton_method(:i18n_key) { key }
|
|
44
|
+
dup_model_name
|
|
45
|
+
else # name is nil for the anonymous intermediate class
|
|
46
|
+
extended_record_base_class.model_name
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
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
|
|
32
57
|
end
|
|
33
58
|
|
|
34
59
|
def sti_name
|
|
35
60
|
extended_record_base_class.sti_name
|
|
36
61
|
end
|
|
37
62
|
|
|
63
|
+
def descends_from_active_record?
|
|
64
|
+
extended_record_base_class.descends_from_active_record?
|
|
65
|
+
end
|
|
66
|
+
|
|
38
67
|
def has_many(name, *args, &extension)
|
|
39
68
|
super(name, *Inheritance.add_foreign_key_option(extended_record_base_class, *args), &extension)
|
|
40
69
|
end
|
|
@@ -49,7 +78,23 @@ module ActiveType
|
|
|
49
78
|
|
|
50
79
|
def find_sti_class(type_name)
|
|
51
80
|
sti_class = super
|
|
52
|
-
|
|
81
|
+
|
|
82
|
+
# Consider this class hierarchy
|
|
83
|
+
# class Parent < ActiveRecord::Base; end
|
|
84
|
+
# class Child < Parent; end
|
|
85
|
+
# class ExtendedParent < ActiveType::Record[Parent]; end
|
|
86
|
+
# class ExtendedChild < ActiveType::Record[Child]; end
|
|
87
|
+
if self < sti_class
|
|
88
|
+
# i.e. ExtendendChild.find(child.id)
|
|
89
|
+
# => self = ExtendedChild; sti_class = Child
|
|
90
|
+
# instantiate as ExtendedChild
|
|
91
|
+
self
|
|
92
|
+
elsif sti_class < extended_record_base_class
|
|
93
|
+
# i.e. ExtendedParent.find(child.id)
|
|
94
|
+
# => sti_class = Child; self = ExtendedParent; extended_record_base_class = Parent
|
|
95
|
+
# There is no really good solution here, since we cannot instantiate as both ExtendedParent
|
|
96
|
+
# and Child. We opt to instantiate as ExtendedParent, since the other option can be
|
|
97
|
+
# achieved by using Parent.find(child.id)
|
|
53
98
|
self
|
|
54
99
|
else
|
|
55
100
|
sti_class
|
|
@@ -77,7 +122,22 @@ module ActiveType
|
|
|
77
122
|
"or overwrite #{name}.inheritance_column to use another column for that information."
|
|
78
123
|
end
|
|
79
124
|
#### our code starts here
|
|
80
|
-
|
|
125
|
+
# Consider this class hierarchy
|
|
126
|
+
# class Parent < ActiveRecord::Base; end
|
|
127
|
+
# class Child < Parent; end
|
|
128
|
+
# class ExtendedParent < ActiveType::Record[Parent]; end
|
|
129
|
+
# class ExtendedChild < ActiveType::Record[Child]; end
|
|
130
|
+
if self < subclass
|
|
131
|
+
# i.e. ExtendendChild.find(child.id)
|
|
132
|
+
# => self = ExtendedChild; subclass = Child
|
|
133
|
+
# instantiate as ExtendedChild
|
|
134
|
+
subclass = self
|
|
135
|
+
elsif subclass < extended_record_base_class
|
|
136
|
+
# i.e. ExtendedParent.find(child.id)
|
|
137
|
+
# => subclass = Child; self = ExtendedParent; extended_record_base_class = Parent
|
|
138
|
+
# There is no really good solution here, since we cannot instantiate as both ExtendedParent
|
|
139
|
+
# and Child. We opt to instantiate as ExtendedParent, since the other option can be
|
|
140
|
+
# achieved by using Parent.find(child.id)
|
|
81
141
|
subclass = self
|
|
82
142
|
end
|
|
83
143
|
#### our code ends here
|
data/lib/active_type/version.rb
CHANGED
|
@@ -73,6 +73,8 @@ module ActiveType
|
|
|
73
73
|
|
|
74
74
|
# Methods for compatibility with gems expecting the ActiveModel::Dirty API.
|
|
75
75
|
def build_dirty_tracking_methods(name)
|
|
76
|
+
return if name.to_s == 'attribute' # clashes with internal methods
|
|
77
|
+
|
|
76
78
|
@module.module_eval <<-BODY, __FILE__, __LINE__ + 1
|
|
77
79
|
def #{name}_was
|
|
78
80
|
virtual_attributes_were["#{name}"]
|
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.4.1
|
|
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: 2020-08-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -123,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
123
|
- !ruby/object:Gem::Version
|
|
124
124
|
version: '0'
|
|
125
125
|
requirements: []
|
|
126
|
-
|
|
127
|
-
rubygems_version: 2.7.8
|
|
126
|
+
rubygems_version: 3.0.8
|
|
128
127
|
signing_key:
|
|
129
128
|
specification_version: 4
|
|
130
129
|
summary: Make any Ruby object quack like ActiveRecord
|