property_sets 3.5.1 → 3.6.0

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: 86b08edc1a23424fd3989657070dcac3482dbc8ade56a6a08b36c06c99a55582
4
- data.tar.gz: b43f0741456a6d62c670110a47e052680d5edc188af2d81175eb7beb3e85e2ff
3
+ metadata.gz: 83bde37b6c1a385dc5372f75424eda44a32211093219e2aa793dc6a42e8a40b6
4
+ data.tar.gz: 33689e9a2946082c6acf3681de60101cd0c1c8e728500fa891adfa91347c6257
5
5
  SHA512:
6
- metadata.gz: 8ac2a0df812e4e43ea688c5997dacc73cb02e2abf10274e2f4c170b32fa0a53ccd36594f1e34fff4154723b4a8e31c5c7701e3a5c59e838b8496dc8a39489f11
7
- data.tar.gz: 74c4b2bc22b462723ade10c4886b85e188ae06c33ea8605b8f12d0b95f22e684672a2e1e3e6b5884345d75d029ab044df4ccae744ea08119e535940ec9b9d17c
6
+ metadata.gz: d5937f372c44d22aee6647680c98be68a1506720e7115b49be0b29e8bdaf85f3f0e80afa2ee3d246875fe2cf076283255101a5d3bc9e34f6aed8643259f9a725
7
+ data.tar.gz: a477ec210da5626275ca6eca932f56d382f68c3f3aca1a74082522cd6614afb48b113cf822948a11c52008f643edca24e71f01c6f34fdc8f5682ed718a8e79de
@@ -163,15 +163,17 @@ module PropertySets
163
163
  end
164
164
 
165
165
  module InstanceMethods
166
- def update_attributes(attributes)
166
+ def update(attributes)
167
167
  update_property_set_attributes(attributes)
168
168
  super
169
169
  end
170
+ alias update_attributes update
170
171
 
171
- def update_attributes!(attributes)
172
+ def update!(attributes)
172
173
  update_property_set_attributes(attributes)
173
174
  super
174
175
  end
176
+ alias update_attributes! update!
175
177
 
176
178
  def update_property_set_attributes(attributes)
177
179
  if attributes && self.class.property_set_index.any?
@@ -182,6 +184,35 @@ module PropertySets
182
184
  end
183
185
  end
184
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
185
216
  end
186
217
 
187
218
  end
@@ -20,11 +20,36 @@ 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
+ unless respond_to?(:delegated_property_set_attributes)
24
+ class_attribute :delegated_property_set_attributes
25
+ end
26
+ self.delegated_property_set_attributes ||= []
27
+
23
28
  mappings.each do |old_attr, new_attr|
24
- define_method(old_attr) { send(setname).send(new_attr) }
29
+ self.delegated_property_set_attributes << old_attr.to_s
30
+ if ActiveRecord.version < Gem::Version.new("5.0")
31
+ attribute old_attr, ActiveRecord::Type::Value.new
32
+ else
33
+ attribute old_attr, ActiveModel::Type::Value.new
34
+ end
35
+ define_method(old_attr) {
36
+ association = send(setname)
37
+ type = association.association_class.type(new_attr)
38
+ association.lookup_value(type, new_attr)
39
+ }
25
40
  alias_method "#{old_attr}_before_type_cast", old_attr
26
41
  define_method("#{old_attr}?") { send(setname).send("#{new_attr}?") }
27
- define_method("#{old_attr}=") { |value| send(setname).send("#{new_attr}=", value) }
42
+ define_method("#{old_attr}=") do |value|
43
+ if send(old_attr) != value
44
+ send("#{old_attr}_will_change!")
45
+ end
46
+ send(setname).send("#{new_attr}=", value)
47
+ super(value) if defined?(super) # Rails 4 does not define this
48
+ end
49
+
50
+ define_method("#{old_attr}_will_change!") do
51
+ attribute_will_change!(old_attr)
52
+ end
28
53
 
29
54
  define_method("#{old_attr}_changed?") do
30
55
  collection_proxy = send(setname)
@@ -40,6 +65,12 @@ module PropertySets
40
65
  end
41
66
  end
42
67
  end
68
+
69
+ # These are not database columns and should not be included in queries but
70
+ # using the attributes API is the only way to track changes in the main model
71
+ if respond_to?(:user_provided_columns)
72
+ self.user_provided_columns.reject!{|k,_| delegated_property_set_attributes.include?(k.to_s) }
73
+ end
43
74
  end
44
75
  end
45
76
  end
@@ -1,3 +1,3 @@
1
1
  module PropertySets
2
- VERSION = "3.5.1"
2
+ VERSION = "3.6.0"
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.1
4
+ version: 3.6.0
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-03-25 00:00:00.000000000 Z
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.1'
22
+ version: '6.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '4.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.1'
32
+ version: '6.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: json
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -100,20 +100,6 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
- - !ruby/object:Gem::Dependency
104
- name: wwtd
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: 0.5.3
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: 0.5.3
117
103
  - !ruby/object:Gem::Dependency
118
104
  name: byebug
119
105
  requirement: !ruby/object:Gem::Requirement
@@ -161,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
147
  - !ruby/object:Gem::Version
162
148
  version: '0'
163
149
  requirements: []
164
- rubygems_version: 3.0.3
150
+ rubygems_version: 3.1.4
165
151
  signing_key:
166
152
  specification_version: 4
167
153
  summary: Property sets for ActiveRecord.