property_sets 3.5.3 → 3.5.4

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: e5b1904f990b0edf7d1a91f1ac6b703f9bddc428d280e031ae4daaa6983f6835
4
- data.tar.gz: cea92b99f11a508d543d9ff4f812e9326ae30aefa06e448619b19ab6dc1dbe02
3
+ metadata.gz: f4e1af4d793c11242f869c3c17e1d25044d301623d1a2f37570c522df9b3b2cf
4
+ data.tar.gz: 6001e124fb8cded395d58d07176a7ff39c14ce8c02e4f97b57a109f3bda0074b
5
5
  SHA512:
6
- metadata.gz: bc1e1b4afd64f05275f2123fb05e9614009eb3ecfb4e8d4940fc74811300a15c2cd7dc13db75ec9d5883d66f81aa2ec4ae637e7039f10ffedbadcb198190c499
7
- data.tar.gz: 976d4c41225d97445c1c9ebf78b19d55d97465c1dce1731fb648d81b1d4e9a35b3446cbfb2e3a5491a6e63c3a1b7172c92533303cc239853c409cb558f951323
6
+ metadata.gz: 91a32d9e89753106a977eb19637ca509b821e8630dcfbd882ef9ac648c6c9043f3dfab4feeb25fe192a946072940efaecf26a50cf014b8fec9ddd6d03ab81ef9
7
+ data.tar.gz: f498e7fab65d9fa4abbcbdce0ea16fe6051ea1d07d41504de521243d032cca7f75ca53c1f51550001fee2a27db43612c9d4869d1a6d86bbb46b18af88b28d805
@@ -184,6 +184,35 @@ module PropertySets
184
184
  end
185
185
  end
186
186
  end
187
+
188
+ def update_columns(attributes)
189
+ if delegated_property_sets?
190
+ attributes = attributes.reject{|k,_| self.class.delegated_property_set_attributes.include?(k.to_s) }
191
+ end
192
+
193
+ super attributes
194
+ end
195
+
196
+ private
197
+
198
+ def delegated_property_sets?
199
+ self.class.respond_to?(:delegated_property_set_attributes)
200
+ end
201
+
202
+ def attributes_for_create(attribute_names)
203
+ super filter_delegated_property_set_attributes(attribute_names)
204
+ end
205
+
206
+ def attributes_for_update(attribute_names)
207
+ super filter_delegated_property_set_attributes(attribute_names)
208
+ end
209
+
210
+ def filter_delegated_property_set_attributes(attribute_names)
211
+ if delegated_property_sets?
212
+ return attribute_names - self.class.delegated_property_set_attributes.to_a
213
+ end
214
+ attribute_names
215
+ end
187
216
  end
188
217
 
189
218
  end
@@ -20,18 +20,26 @@ module PropertySets
20
20
  def delegate_to_property_set(setname, mappings)
21
21
  raise "Second argument must be a Hash" unless mappings.is_a?(Hash)
22
22
 
23
+ @delegated_property_set_attributes ||= []
24
+
23
25
  mappings.each do |old_attr, new_attr|
26
+ self.delegated_property_set_attributes << old_attr.to_s
24
27
  if ActiveRecord.version < Gem::Version.new("5.0")
25
28
  attribute old_attr, ActiveRecord::Type::Value.new
26
29
  else
27
30
  attribute old_attr, ActiveModel::Type::Value.new
28
31
  end
29
- define_method(old_attr) { send(setname).send(new_attr) }
32
+ define_method(old_attr) {
33
+ association = send(setname)
34
+ type = association.association_class.type(new_attr)
35
+ association.lookup_value(type, new_attr)
36
+ }
30
37
  alias_method "#{old_attr}_before_type_cast", old_attr
31
38
  define_method("#{old_attr}?") { send(setname).send("#{new_attr}?") }
32
39
  define_method("#{old_attr}=") do |value|
40
+ attribute_will_change!(old_attr) if old_attr != value && !defined?(super)
33
41
  send(setname).send("#{new_attr}=", value)
34
- super(value)
42
+ super(value) if defined?(super)
35
43
  end
36
44
 
37
45
  define_method("#{old_attr}_changed?") do
@@ -48,6 +56,16 @@ module PropertySets
48
56
  end
49
57
  end
50
58
  end
59
+
60
+ # These are not database columns and should not be included in queries but
61
+ # using the attributes API is the only way to track changes in the main model
62
+ if respond_to?(:user_provided_columns)
63
+ self.user_provided_columns.reject!{|k,_| @delegated_property_set_attributes.include?(k.to_s) }
64
+ end
65
+ end
66
+
67
+ def delegated_property_set_attributes
68
+ @delegated_property_set_attributes
51
69
  end
52
70
  end
53
71
  end
@@ -1,3 +1,3 @@
1
1
  module PropertySets
2
- VERSION = "3.5.3"
2
+ VERSION = "3.5.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: property_sets
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.3
4
+ version: 3.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morten Primdahl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-02 00:00:00.000000000 Z
11
+ date: 2020-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -161,7 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
- rubygems_version: 3.0.3
164
+ rubyforge_project:
165
+ rubygems_version: 2.7.6.2
165
166
  signing_key:
166
167
  specification_version: 4
167
168
  summary: Property sets for ActiveRecord.