glue_gun_dsl 0.1.23 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/glue_gun/model.rb +31 -10
- data/lib/glue_gun/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2fd5acfe5156d1581b51d68d5598ef181faea52ec3c46d730fef428f7faba15
|
4
|
+
data.tar.gz: c6185af99fd906dd841582b283b4559d8f1fbc4e3046086d7cf4a15ac5e1b1d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 587486d0afa4a7cde26ffc1a6d6a766123db4c09111b4f2e9d3b4f9f17651856a6a587b81832cb78fe93fa6d0f9f23cae88c145a61ac9905968508ffb6f8b7fc
|
7
|
+
data.tar.gz: 14d80f872b13ada859d605068799e8331136c36db88e9dd5ba81eadd93b34b7362918e08eb3e1a48848e8b42ea4477f597d43cc1b3633205dfdc2d2e84d66b5d
|
data/lib/glue_gun/model.rb
CHANGED
@@ -15,6 +15,19 @@ module GlueGun
|
|
15
15
|
|
16
16
|
# Set default service attribute name based on the class name
|
17
17
|
self.service_attribute_name = "#{name.demodulize.underscore}_service".to_sym
|
18
|
+
|
19
|
+
def assign_attributes(attributes)
|
20
|
+
return if attributes.blank?
|
21
|
+
|
22
|
+
attributes = attributes.deep_symbolize_keys
|
23
|
+
db_attributes = self.class.extract_db_attributes(attributes)
|
24
|
+
|
25
|
+
# Assign database attributes
|
26
|
+
super(db_attributes)
|
27
|
+
|
28
|
+
assign_service_attributes(attributes)
|
29
|
+
end
|
30
|
+
alias_method :attributes=, :assign_attributes
|
18
31
|
end
|
19
32
|
|
20
33
|
class_methods do
|
@@ -35,11 +48,7 @@ module GlueGun
|
|
35
48
|
|
36
49
|
record = where(db_attributes).first_or_initialize(attributes)
|
37
50
|
|
38
|
-
if record.new_record?
|
39
|
-
record.save!
|
40
|
-
else
|
41
|
-
record.send(:build_service_object, attributes)
|
42
|
-
end
|
51
|
+
record.save! if record.new_record?
|
43
52
|
yield record if block_given?
|
44
53
|
|
45
54
|
record
|
@@ -52,11 +61,7 @@ module GlueGun
|
|
52
61
|
|
53
62
|
record = where(db_attributes).first_or_initialize(attributes)
|
54
63
|
|
55
|
-
if record.new_record?
|
56
|
-
record.save
|
57
|
-
else
|
58
|
-
record.send(:build_service_object, attributes)
|
59
|
-
end
|
64
|
+
record.save if record.new_record?
|
60
65
|
yield record if block_given?
|
61
66
|
|
62
67
|
record
|
@@ -79,6 +84,22 @@ module GlueGun
|
|
79
84
|
build_service_object(attributes)
|
80
85
|
end
|
81
86
|
|
87
|
+
def assign_service_attributes(attributes)
|
88
|
+
return if attributes.blank?
|
89
|
+
|
90
|
+
service_object = instance_variable_get("@#{service_attribute_name}")
|
91
|
+
return unless service_object.present?
|
92
|
+
|
93
|
+
extract_service_attributes(attributes, service_object.class).each do |attr_name, value|
|
94
|
+
unless service_object.respond_to?("#{attr_name}=")
|
95
|
+
raise NoMethodError, "Undefined attribute #{attr_name} for #{service_object.class.name}"
|
96
|
+
end
|
97
|
+
|
98
|
+
service_object.send("#{attr_name}=", value)
|
99
|
+
attribute_will_change!(attr_name.to_s)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
82
103
|
private
|
83
104
|
|
84
105
|
def build_service_object(attributes)
|
data/lib/glue_gun/version.rb
CHANGED