property_sets 3.5.0 → 3.5.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b451948a4cd57b5387dcd5cd4869b07d0fca6b6107cc9a9ee3ca8cfdd63af8cd
|
4
|
+
data.tar.gz: d40876f744ec7d356173ec010f197e3252986bfc80679fbe9212ab847b15fe73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc88f6195a44c5da452f19652cfa0ca5c2e59c315ebc95933182c286d03553779f0f8a8bd3fbe5d11ce7a27d0dc3702619dc2c5662556b874604cccb7635c202
|
7
|
+
data.tar.gz: db1a33e34e8ba06d0a0db052b0fb08fafd6d644acfbbb13fcada92471f7a2cae90801855cc815608b99471dbf65e68ece98c0bc4fca20ff18b2f0dac1195c184
|
@@ -163,15 +163,17 @@ module PropertySets
|
|
163
163
|
end
|
164
164
|
|
165
165
|
module InstanceMethods
|
166
|
-
def
|
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
|
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
|
-
|
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}=")
|
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
|
@@ -137,7 +137,7 @@ module PropertySets
|
|
137
137
|
@owner_class_sym = owner_class_name.underscore.to_sym
|
138
138
|
belongs_to owner_class_sym
|
139
139
|
validates_presence_of owner_class_sym
|
140
|
-
validates_uniqueness_of :name, :scope => owner_class_key_sym
|
140
|
+
validates_uniqueness_of :name, :scope => owner_class_key_sym, :case_sensitive => false
|
141
141
|
attr_accessible owner_class_key_sym, owner_class_sym if defined?(ProtectedAttributes)
|
142
142
|
end
|
143
143
|
|
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.
|
4
|
+
version: 3.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morten Primdahl
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -146,7 +146,7 @@ homepage: http://github.com/zendesk/property_sets
|
|
146
146
|
licenses:
|
147
147
|
- MIT
|
148
148
|
metadata: {}
|
149
|
-
post_install_message:
|
149
|
+
post_install_message:
|
150
150
|
rdoc_options: []
|
151
151
|
require_paths:
|
152
152
|
- lib
|
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
version: '0'
|
163
163
|
requirements: []
|
164
164
|
rubygems_version: 3.0.3
|
165
|
-
signing_key:
|
165
|
+
signing_key:
|
166
166
|
specification_version: 4
|
167
167
|
summary: Property sets for ActiveRecord.
|
168
168
|
test_files: []
|