active_type 1.3.0 → 1.4.2
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/CHANGELOG.md +40 -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.lock +2 -2
- data/lib/active_type/nested_attributes/nests_one_association.rb +5 -2
- data/lib/active_type/record_extension/inheritance.rb +27 -2
- data/lib/active_type/version.rb +1 -1
- data/lib/active_type/virtual_attributes.rb +29 -10
- 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: dc8f689fdb28d28edb7fc550d21e0c9d4810f298da570e9e8dc223a028c09dc1
|
4
|
+
data.tar.gz: 7f41ea5cd75b455190740c263f836d42cd268e0ab15e3143c9c8dfedb21e0b04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da0b114cb9f97509bc8becad66a553538cbb362d07f9c8a6f1f17d7298282c302a83f477669110fd564f269b9dda5c2a009df41d40990a030044b90be869b03e
|
7
|
+
data.tar.gz: a9c59ed853ad1972ffd1d13d73eb452945f7c882bff1bc0dec49dec26a4b59c726b14381dd7a75f3905f0a5052906d027e8f500910e9b0395e6bc6a076639193
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,45 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
|
5
5
|
## Unreleased changes
|
6
6
|
|
7
|
+
## 1.4.2 (2020-09-17)
|
8
|
+
|
9
|
+
* Fixed: Assigning values to virtual attributes through internal setter methods (e.g. `_write_attribute`) no longer results in "can't write unknown attribute" errors.
|
10
|
+
|
11
|
+
## 1.4.1 (2020-08-05)
|
12
|
+
|
13
|
+
* Fixed: Avoid `Module#parents` deprecation warning on Rails 6. Thanks to @cilim.
|
14
|
+
|
15
|
+
## 1.4.0 (2020-07-27)
|
16
|
+
|
17
|
+
* Extended records now use their own I18n namespace when looking up translations for models or attributes.
|
18
|
+
If the extended record's namespace does not contain a translation, the lookup will fall back to the
|
19
|
+
base record's namespace.
|
20
|
+
|
21
|
+
For instance, given the following class hierarchy:
|
22
|
+
|
23
|
+
```
|
24
|
+
class User < ActiveRecord::Base
|
25
|
+
end
|
26
|
+
|
27
|
+
class User::Form < ActiveType::Record[User]
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
The call `ExtendedParent.human_attribute_name(:foo)` would first look up the key in
|
32
|
+
`activerecord.attributes.user/form` first, then falls back to `activerecord.attributes.user`.
|
33
|
+
|
34
|
+
Thank you @fsateler!
|
35
|
+
|
36
|
+
|
37
|
+
## 1.3.2 (2020-06-16)
|
38
|
+
|
39
|
+
* Fixed: `nests_one` association record building used empty hash instead of passed in attributes. Credit to @chriscz.
|
40
|
+
|
41
|
+
|
42
|
+
## 1.3.1 (2020-03-31)
|
43
|
+
|
44
|
+
* Fixed: Avoid #change_association breaking for polymorphic associations. Thanks to @lucthev.
|
45
|
+
|
7
46
|
|
8
47
|
## 1.3.0 (2019-09-26)
|
9
48
|
|
@@ -26,7 +65,7 @@ All notable changes to this project will be documented in this file.
|
|
26
65
|
end
|
27
66
|
```
|
28
67
|
|
29
|
-
|
68
|
+
querying
|
30
69
|
|
31
70
|
```
|
32
71
|
ExtendedParent.all
|
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.lock
CHANGED
@@ -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,7 +28,32 @@ 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
|
data/lib/active_type/version.rb
CHANGED
@@ -144,28 +144,47 @@ module ActiveType
|
|
144
144
|
@virtual_attributes_cache ||= {}
|
145
145
|
end
|
146
146
|
|
147
|
-
def
|
147
|
+
def read_existing_virtual_attribute(name, &block_when_not_virtual)
|
148
148
|
if self.singleton_class._has_virtual_column?(name)
|
149
149
|
read_virtual_attribute(name)
|
150
150
|
else
|
151
|
-
|
151
|
+
yield
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
-
|
156
|
-
def _read_attribute(name)
|
155
|
+
def write_existing_virtual_attribute(name, value, &block_when_not_virtual)
|
157
156
|
if self.singleton_class._has_virtual_column?(name)
|
158
|
-
|
157
|
+
write_virtual_attribute(name, value)
|
159
158
|
else
|
160
|
-
|
159
|
+
yield
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def [](name)
|
164
|
+
read_existing_virtual_attribute(name) { super }
|
165
|
+
end
|
166
|
+
|
167
|
+
if ActiveRecord::VERSION::STRING >= '4.2.0'
|
168
|
+
def _read_attribute(name)
|
169
|
+
read_existing_virtual_attribute(name) { super }
|
170
|
+
end
|
171
|
+
else
|
172
|
+
def read_attribute(name)
|
173
|
+
read_existing_virtual_attribute(name) { super }
|
161
174
|
end
|
162
175
|
end
|
163
176
|
|
164
177
|
def []=(name, value)
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
178
|
+
write_existing_virtual_attribute(name, value) { super }
|
179
|
+
end
|
180
|
+
|
181
|
+
if ActiveRecord::VERSION::STRING >= '5.2.0'
|
182
|
+
def _write_attribute(name, value)
|
183
|
+
write_existing_virtual_attribute(name, value) { super }
|
184
|
+
end
|
185
|
+
else
|
186
|
+
def write_attribute(name, value)
|
187
|
+
write_existing_virtual_attribute(name, value) { super }
|
169
188
|
end
|
170
189
|
end
|
171
190
|
|
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.2
|
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-09-17 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.3
|
128
127
|
signing_key:
|
129
128
|
specification_version: 4
|
130
129
|
summary: Make any Ruby object quack like ActiveRecord
|