active_type 1.3.0 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5e4919b7989f9d2ce9468d47196b1142270e6b3c2cce7e01945c20c36f4d2b8
4
- data.tar.gz: 258bdcde75ea6cbe3c5ef9fb55cd6b0a140a0a8e251745b6d00a0ec7af1834d5
3
+ metadata.gz: dc8f689fdb28d28edb7fc550d21e0c9d4810f298da570e9e8dc223a028c09dc1
4
+ data.tar.gz: 7f41ea5cd75b455190740c263f836d42cd268e0ab15e3143c9c8dfedb21e0b04
5
5
  SHA512:
6
- metadata.gz: ccdd4e34bfbee28b18560bc03a615f52ea4b13ee8a0ba5a33fd19552a2324142108746898159f9ff81ec30cdb420c4380d72c0b695067a7c83a58450be246645
7
- data.tar.gz: 8a91a6d3e6587f22c1dc18129f1fb35821431057d44b0732a7ab25e6f02132edcdc134b7d26735d1efbb5ae8015b33d6d055c2a6336914107b17b0f52209b0b2
6
+ metadata.gz: da0b114cb9f97509bc8becad66a553538cbb362d07f9c8a6f1f17d7298282c302a83f477669110fd564f269b9dda5c2a009df41d40990a030044b90be869b03e
7
+ data.tar.gz: a9c59ed853ad1972ffd1d13d73eb452945f7c882bff1bc0dec49dec26a4b59c726b14381dd7a75f3905f0a5052906d027e8f500910e9b0395e6bc6a076639193
@@ -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
- queriying
68
+ querying
30
69
 
31
70
  ```
32
71
  ExtendedParent.all
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.3.0)
4
+ active_type (1.4.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -54,4 +54,4 @@ DEPENDENCIES
54
54
  rspec (~> 3.4)
55
55
 
56
56
  BUNDLED WITH
57
- 2.0.2
57
+ 2.1.4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.3.0)
4
+ active_type (1.4.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -54,4 +54,4 @@ DEPENDENCIES
54
54
  sqlite3
55
55
 
56
56
  BUNDLED WITH
57
- 2.0.2
57
+ 2.1.4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.3.0)
4
+ active_type (1.4.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -58,4 +58,4 @@ DEPENDENCIES
58
58
  rspec (~> 3.4)
59
59
 
60
60
  BUNDLED WITH
61
- 2.0.2
61
+ 2.1.4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.3.0)
4
+ active_type (1.4.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -58,4 +58,4 @@ DEPENDENCIES
58
58
  rspec (~> 3.4)
59
59
 
60
60
  BUNDLED WITH
61
- 2.0.2
61
+ 2.1.4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.3.0)
4
+ active_type (1.4.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -58,4 +58,4 @@ DEPENDENCIES
58
58
  sqlite3
59
59
 
60
60
  BUNDLED WITH
61
- 2.0.2
61
+ 2.1.4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.3.0)
4
+ active_type (1.4.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -56,4 +56,4 @@ DEPENDENCIES
56
56
  rspec (~> 3.4)
57
57
 
58
58
  BUNDLED WITH
59
- 2.0.2
59
+ 2.1.4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.3.0)
4
+ active_type (1.4.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -56,4 +56,4 @@ DEPENDENCIES
56
56
  rspec (~> 3.4)
57
57
 
58
58
  BUNDLED WITH
59
- 2.0.2
59
+ 2.1.4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.3.0)
4
+ active_type (1.4.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -56,4 +56,4 @@ DEPENDENCIES
56
56
  sqlite3
57
57
 
58
58
  BUNDLED WITH
59
- 2.0.2
59
+ 2.1.4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.3.0)
4
+ active_type (1.4.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -56,4 +56,4 @@ DEPENDENCIES
56
56
  rspec (~> 3.4)
57
57
 
58
58
  BUNDLED WITH
59
- 2.0.2
59
+ 2.1.4
@@ -30,8 +30,11 @@ module ActiveType
30
30
  end
31
31
  end
32
32
  elsif !destroy
33
- assigned_child ||= add_child(parent, build_child(parent, {}))
34
- assigned_child.attributes = attributes
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
- extended_record_base_class.model_name
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
@@ -1,3 +1,3 @@
1
1
  module ActiveType
2
- VERSION = '1.3.0'
2
+ VERSION = '1.4.2'
3
3
  end
@@ -144,28 +144,47 @@ module ActiveType
144
144
  @virtual_attributes_cache ||= {}
145
145
  end
146
146
 
147
- def [](name)
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
- super
151
+ yield
152
152
  end
153
153
  end
154
154
 
155
- # ActiveRecord 4.2.1
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
- read_virtual_attribute(name)
157
+ write_virtual_attribute(name, value)
159
158
  else
160
- super
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
- if self.singleton_class._has_virtual_column?(name)
166
- write_virtual_attribute(name, value)
167
- else
168
- super
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.3.0
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: 2019-09-26 00:00:00.000000000 Z
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
- rubyforge_project:
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