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 +4 -4
- data/lib/property_sets/active_record_extension.rb +29 -0
- data/lib/property_sets/delegator.rb +20 -2
- data/lib/property_sets/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4e1af4d793c11242f869c3c17e1d25044d301623d1a2f37570c522df9b3b2cf
|
4
|
+
data.tar.gz: 6001e124fb8cded395d58d07176a7ff39c14ce8c02e4f97b57a109f3bda0074b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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) {
|
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
|
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.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-
|
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
|
-
|
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.
|