relaxo-model 0.17.3 → 0.18.0
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/relaxo/model/base.rb +2 -2
- data/lib/relaxo/model/component.rb +22 -22
- data/lib/relaxo/model/document.rb +14 -14
- data/lib/relaxo/model/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43646c8e87ba1baad72dd21037a91817468427e6c990f82ed1f6201d319961f7
|
4
|
+
data.tar.gz: 3b7e4d1c13908a5fc015e2160e037b3492cf5c41f7ce1b17773de8aaa9bbea6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a34f73d1f6931122401aa1b3c678adf6894ed9c275ee03420f624d732eafeaac28e854a8f192e34ad3fb15eb3bc7bd2b77e72283620bc4fb165d31bc6924c91
|
7
|
+
data.tar.gz: 0dde3caeb52c3cb6ee779986db3568a7acef6fb1786be0b302505ab0c3ca8788be515c632cab06262ec634d4becf5a3f551168b0b3c0a3ae19593e5d65a2b1eb
|
data/lib/relaxo/model/base.rb
CHANGED
@@ -120,9 +120,9 @@ module Relaxo
|
|
120
120
|
@properties[name] = klass
|
121
121
|
|
122
122
|
self.send(:define_method, name) do
|
123
|
-
if @changed.include?
|
123
|
+
if @changed.include?(name)
|
124
124
|
return @changed[name]
|
125
|
-
elsif @attributes.include?
|
125
|
+
elsif @attributes.include?(name)
|
126
126
|
if klass
|
127
127
|
value = @attributes[name]
|
128
128
|
|
@@ -68,32 +68,32 @@ module Relaxo
|
|
68
68
|
@changed.delete(key)
|
69
69
|
@attributes.delete(key)
|
70
70
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
enumerator = enumerator.select{|key, value| self.class.properties.include? key.to_sym}
|
77
|
-
elsif only.respond_to? :include?
|
78
|
-
enumerator = enumerator.select{|key, value| only.include? key.to_sym}
|
79
|
-
end
|
80
|
-
|
81
|
-
enumerator.each do |key, value|
|
71
|
+
|
72
|
+
ALL = Hash.new(true)
|
73
|
+
|
74
|
+
def assign(primative_attributes, only = ALL)
|
75
|
+
primative_attributes.each do |key, value|
|
82
76
|
key = key.to_sym
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
77
|
+
case mapping = only[key]
|
78
|
+
when true
|
79
|
+
# Assign from primitive value:
|
80
|
+
if klass = self.class.properties[key]
|
81
|
+
value = klass.convert_from_primative(@dataset, value)
|
82
|
+
end
|
83
|
+
|
84
|
+
self[key] = value
|
85
|
+
when false, nil
|
86
|
+
# Ignore:
|
87
|
+
next
|
88
|
+
else
|
89
|
+
# Nested assignment:
|
90
|
+
self[key].assign(value, mapping)
|
89
91
|
end
|
90
|
-
|
91
|
-
self[key] = value
|
92
92
|
end
|
93
93
|
|
94
94
|
return self
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
def [] name
|
98
98
|
if self.class.properties.include? name
|
99
99
|
self.send(name)
|
@@ -101,7 +101,7 @@ module Relaxo
|
|
101
101
|
raise KeyError.new(name)
|
102
102
|
end
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def []= name, value
|
106
106
|
if self.class.properties.include? name
|
107
107
|
self.send("#{name}=", value)
|
@@ -109,7 +109,7 @@ module Relaxo
|
|
109
109
|
raise KeyError.new(name)
|
110
110
|
end
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
def validate(changeset)
|
114
114
|
# Do nothing :)
|
115
115
|
end
|
@@ -109,7 +109,7 @@ module Relaxo
|
|
109
109
|
end
|
110
110
|
|
111
111
|
# Update any calculations:
|
112
|
-
def before_save
|
112
|
+
def before_save(changeset)
|
113
113
|
end
|
114
114
|
|
115
115
|
def after_save
|
@@ -148,34 +148,34 @@ module Relaxo
|
|
148
148
|
end
|
149
149
|
|
150
150
|
# Save the model object.
|
151
|
-
def save(
|
152
|
-
|
151
|
+
def save(changeset)
|
152
|
+
before_save(changeset)
|
153
153
|
|
154
|
-
|
154
|
+
return if persisted? and @changed.empty?
|
155
155
|
|
156
|
-
if errors = self.validate(
|
156
|
+
if errors = self.validate(changeset)
|
157
157
|
return errors
|
158
158
|
end
|
159
159
|
|
160
160
|
existing_paths = persisted? ? paths.to_a : []
|
161
161
|
|
162
162
|
# Write data, check if any actual changes made:
|
163
|
-
object =
|
163
|
+
object = changeset.append(self.dump)
|
164
164
|
return if object == @object
|
165
165
|
|
166
166
|
existing_paths.each do |path|
|
167
|
-
|
167
|
+
changeset.delete(path)
|
168
168
|
end
|
169
169
|
|
170
170
|
paths do |path|
|
171
|
-
if
|
171
|
+
if changeset.exist?(path)
|
172
172
|
raise KeyError, "Dataset already contains path: #{path}, when inserting #{@attributes.inspect}"
|
173
173
|
end
|
174
174
|
|
175
|
-
|
175
|
+
changeset.write(path, object)
|
176
176
|
end
|
177
177
|
|
178
|
-
@dataset =
|
178
|
+
@dataset = changeset
|
179
179
|
@object = object
|
180
180
|
|
181
181
|
after_save
|
@@ -183,8 +183,8 @@ module Relaxo
|
|
183
183
|
return true
|
184
184
|
end
|
185
185
|
|
186
|
-
def save!(
|
187
|
-
result = self.save(
|
186
|
+
def save!(changeset)
|
187
|
+
result = self.save(changeset)
|
188
188
|
|
189
189
|
if result != true
|
190
190
|
raise ValidationFailure.new(self, result)
|
@@ -199,13 +199,13 @@ module Relaxo
|
|
199
199
|
def after_delete
|
200
200
|
end
|
201
201
|
|
202
|
-
def delete(
|
202
|
+
def delete(changeset)
|
203
203
|
before_delete
|
204
204
|
|
205
205
|
@changed.clear
|
206
206
|
|
207
207
|
paths.each do |path|
|
208
|
-
|
208
|
+
changeset.delete(path)
|
209
209
|
end
|
210
210
|
|
211
211
|
after_delete
|
data/lib/relaxo/model/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaxo-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|