redis_assist 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redis_assist/base.rb +43 -19
- data/lib/redis_assist/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba4b1d6aced02e94d0bb9478ea2345279c6e9666
|
4
|
+
data.tar.gz: d2d622280520951718d4144141ed24eae5565c87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07bc191b9dd9f3341950699df52b43c06516e8e1f40f84148f62e3544923b94956a32a7dba0ce8ee051e66cc009844e95db9983ed9ce479d28b0c18073e25161
|
7
|
+
data.tar.gz: 0ca7ce11c47d191e01e3c5dee3226f62f234ac661dc84dcf0d1bb1aeedadf90d3342b9e574e2c9aa3d8405d1942cb89c2f677201e9de59a57a1b22beab5bf65c
|
data/lib/redis_assist/base.rb
CHANGED
@@ -174,36 +174,21 @@ module RedisAssist
|
|
174
174
|
|
175
175
|
def define_list(name)
|
176
176
|
define_method(name) do
|
177
|
-
|
178
|
-
|
179
|
-
if !lists[name] && opts[:default]
|
180
|
-
opts[:default]
|
181
|
-
else
|
182
|
-
send("#{name}=", lists[name].value) if lists[name].is_a?(Redis::Future)
|
183
|
-
lists[name]
|
184
|
-
end
|
177
|
+
read_list(name)
|
185
178
|
end
|
186
179
|
|
187
180
|
define_method("#{name}=") do |val|
|
188
|
-
|
189
|
-
lists[name] = val
|
181
|
+
write_list(name, val)
|
190
182
|
end
|
191
183
|
end
|
192
184
|
|
193
185
|
def define_hash(name)
|
194
186
|
define_method(name) do
|
195
|
-
|
196
|
-
|
197
|
-
if !hashes[name] && opts[:default]
|
198
|
-
opts[:default]
|
199
|
-
else
|
200
|
-
self.send("#{name}=", hashes[name].value)
|
201
|
-
end
|
187
|
+
read_hash(name)
|
202
188
|
end
|
203
189
|
|
204
190
|
define_method("#{name}=") do |val|
|
205
|
-
|
206
|
-
hashes[name] = val
|
191
|
+
write_hash(name, val)
|
207
192
|
end
|
208
193
|
end
|
209
194
|
|
@@ -247,6 +232,8 @@ module RedisAssist
|
|
247
232
|
raise "RedisAssist: #{self.class.name} does not support attributes: #{attrs.keys.join(', ')}" if attrs.length > 0
|
248
233
|
end
|
249
234
|
|
235
|
+
|
236
|
+
# Transform and read a standard attribute
|
250
237
|
def read_attribute(name)
|
251
238
|
if attributes.is_a?(Redis::Future)
|
252
239
|
value = attributes.value
|
@@ -256,9 +243,46 @@ module RedisAssist
|
|
256
243
|
self.class.transform(:from, name, attributes[name])
|
257
244
|
end
|
258
245
|
|
246
|
+
# Transform and read a list attribute
|
247
|
+
def read_list(name)
|
248
|
+
opts = self.class.persisted_attrs[name]
|
249
|
+
|
250
|
+
if !lists[name] && opts[:default]
|
251
|
+
opts[:default]
|
252
|
+
else
|
253
|
+
send("#{name}=", lists[name].value) if lists[name].is_a?(Redis::Future)
|
254
|
+
lists[name]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
# Transform and read a hash attribute
|
259
|
+
def read_hash(name)
|
260
|
+
opts = self.class.persisted_attrs[name]
|
261
|
+
|
262
|
+
if !hashes[name] && opts[:default]
|
263
|
+
opts[:default]
|
264
|
+
else
|
265
|
+
self.send("#{name}=", hashes[name].value)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
|
270
|
+
# Transform and write a standard attribute value
|
259
271
|
def write_attribute(name, val)
|
260
272
|
attributes[name] = self.class.transform(:to, name, val)
|
261
273
|
end
|
274
|
+
|
275
|
+
# Transform and write a list value
|
276
|
+
def write_list(name, val)
|
277
|
+
raise "RedisAssist: tried to store a #{val.class.name} as Array" unless val.is_a?(Array)
|
278
|
+
lists[name] = val
|
279
|
+
end
|
280
|
+
|
281
|
+
# Transform and write a hash attribute
|
282
|
+
def write_hash(name, val)
|
283
|
+
raise "RedisAssist: tried to store a #{val.class.name} as Hash" unless val.is_a?(Hash)
|
284
|
+
hashes[name] = val
|
285
|
+
end
|
262
286
|
|
263
287
|
def saved?
|
264
288
|
!!(new_record?.eql?(false) && id)
|
data/lib/redis_assist/version.rb
CHANGED