redis_assist 0.4.4 → 0.4.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fca3422e9a8b3aa9e52ec50f8375e7e15a17195
4
- data.tar.gz: 92852c0ed3f94342753e0f34a96acfbe6a645d3a
3
+ metadata.gz: ba4b1d6aced02e94d0bb9478ea2345279c6e9666
4
+ data.tar.gz: d2d622280520951718d4144141ed24eae5565c87
5
5
  SHA512:
6
- metadata.gz: 05a45f208034e395f255814ee7a466a7bb8a811438f5216f2179e9d493f2af4d20d8bc9c512c0003519e027e438336403fe7f1d7b7a83223a3e25f59976ab985
7
- data.tar.gz: 69194d125abf3d9f3bbfdf5da1bf8075f3b38c6a58578b5d09bd2daf915ecd6788bffa1c99d2f60ec2d4569ef9afdc0f04ee6691ba6971b31160454ce3c56261
6
+ metadata.gz: 07bc191b9dd9f3341950699df52b43c06516e8e1f40f84148f62e3544923b94956a32a7dba0ce8ee051e66cc009844e95db9983ed9ce479d28b0c18073e25161
7
+ data.tar.gz: 0ca7ce11c47d191e01e3c5dee3226f62f234ac661dc84dcf0d1bb1aeedadf90d3342b9e574e2c9aa3d8405d1942cb89c2f677201e9de59a57a1b22beab5bf65c
@@ -174,36 +174,21 @@ module RedisAssist
174
174
 
175
175
  def define_list(name)
176
176
  define_method(name) do
177
- opts = self.class.persisted_attrs[name]
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
- raise "RedisAssist: tried to store a #{val.class.name} as Array" unless val.is_a?(Array)
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
- opts = self.class.persisted_attrs[name]
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
- raise "RedisAssist: tried to store a #{val.class.name} as Hash" unless val.is_a?(Hash)
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)
@@ -1,3 +1,3 @@
1
1
  module RedisAssist
2
- VERSION = '0.4.4' unless defined?(::RedisAssist::VERSION)
2
+ VERSION = '0.4.5' unless defined?(::RedisAssist::VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_assist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Love