active_redis_orm 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_redis/attributes.rb +24 -24
- data/lib/active_redis/nil_object.rb +12 -0
- data/lib/active_redis/version.rb +1 -1
- data/lib/active_redis_orm.rb +7 -1
- data/spec/lib/active_redis/nil_object_spec.rb +7 -0
- data/spec/lib/active_redis_spec.rb +15 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b411bfb8f667027da1b252715b2558fb963a2a8
|
4
|
+
data.tar.gz: 55692c9536d1fbeb6be3ed325785f487f2c97c16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e22e86f443f986590ab0e9bc155d8d9c0d414fb0c1f958f3fe4440ede5141b18f09d44fc4dacba6fd34b8d2f7a48ef8d472a861b7555dbe4acda9e02e796ac59
|
7
|
+
data.tar.gz: 29fc748ea40c80f9f2f0d792fcbec6ba408d7a730bce41239159aa6df172134ed92a133a53959af7ac44e784599eaf2a635c133386ceb617502ad9b86a2129ff
|
@@ -39,8 +39,8 @@ module ActiveRedis
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def define_field(field_name, options)
|
42
|
-
|
43
|
-
|
42
|
+
define_attribute_method field_name
|
43
|
+
attributes_module.module_eval %Q{
|
44
44
|
def #{field_name}_redis_key
|
45
45
|
"#{self.redis_namespace}:\#{id}:#{field_name}"
|
46
46
|
end
|
@@ -88,12 +88,12 @@ module ActiveRedis
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def string_field(field_name, options)
|
91
|
-
|
91
|
+
attributes_module.module_eval %Q{
|
92
92
|
def #{field_name}_object
|
93
93
|
Redis::Value.new(#{field_name}_redis_key)
|
94
94
|
end
|
95
95
|
|
96
|
-
def #{field_name}
|
96
|
+
def #{field_name}_val
|
97
97
|
@attributes[:#{field_name}] ||= begin
|
98
98
|
value = #{field_name}_object.value
|
99
99
|
value.nil? ? value : value.to_s
|
@@ -119,12 +119,12 @@ module ActiveRedis
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def integer_field(field_name, options)
|
122
|
-
|
122
|
+
attributes_module.module_eval %Q{
|
123
123
|
def #{field_name}_object
|
124
124
|
Redis::Value.new(#{field_name}_redis_key)
|
125
125
|
end
|
126
126
|
|
127
|
-
def #{field_name}
|
127
|
+
def #{field_name}_val
|
128
128
|
@attributes[:#{field_name}] ||= begin
|
129
129
|
value = #{field_name}_object.value
|
130
130
|
value.nil? ? value : value.to_i
|
@@ -153,12 +153,12 @@ module ActiveRedis
|
|
153
153
|
end
|
154
154
|
|
155
155
|
def float_field(field_name, options)
|
156
|
-
|
156
|
+
attributes_module.module_eval %Q{
|
157
157
|
def #{field_name}_object
|
158
158
|
Redis::Value.new(#{field_name}_redis_key)
|
159
159
|
end
|
160
160
|
|
161
|
-
def #{field_name}
|
161
|
+
def #{field_name}_val
|
162
162
|
@attributes[:#{field_name}] ||= begin
|
163
163
|
value = #{field_name}_object.value
|
164
164
|
value.nil? ? value : value.to_f
|
@@ -187,12 +187,12 @@ module ActiveRedis
|
|
187
187
|
end
|
188
188
|
|
189
189
|
def boolean_field(field_name, options)
|
190
|
-
|
190
|
+
attributes_module.module_eval %Q{
|
191
191
|
def #{field_name}_object
|
192
192
|
Redis::Value.new(#{field_name}_redis_key)
|
193
193
|
end
|
194
194
|
|
195
|
-
def #{field_name}
|
195
|
+
def #{field_name}_val
|
196
196
|
return @attributes[:#{field_name}] if @attributes[:#{field_name}].boolean?
|
197
197
|
@attributes[:#{field_name}] ||= begin
|
198
198
|
value = #{field_name}_object.value
|
@@ -224,12 +224,12 @@ module ActiveRedis
|
|
224
224
|
end
|
225
225
|
|
226
226
|
def counter_field(field_name, options)
|
227
|
-
|
227
|
+
attributes_module.module_eval %Q{
|
228
228
|
def #{field_name}_object
|
229
229
|
Redis::Counter.new(#{field_name}_redis_key)
|
230
230
|
end
|
231
231
|
|
232
|
-
def #{field_name}
|
232
|
+
def #{field_name}_val
|
233
233
|
@attributes[:#{field_name}] ||= #{field_name}_object.value.to_i
|
234
234
|
end
|
235
235
|
|
@@ -254,12 +254,12 @@ module ActiveRedis
|
|
254
254
|
end
|
255
255
|
|
256
256
|
def list_field(field_name, options)
|
257
|
-
|
257
|
+
attributes_module.module_eval %Q{
|
258
258
|
def #{field_name}_object
|
259
259
|
Redis::List.new(#{field_name}_redis_key)
|
260
260
|
end
|
261
261
|
|
262
|
-
def #{field_name}
|
262
|
+
def #{field_name}_val
|
263
263
|
@attributes[:#{field_name}] ||= begin
|
264
264
|
ActiveRedis::DirtyObjects::Array.new(#{field_name}_object.values)
|
265
265
|
end
|
@@ -296,12 +296,12 @@ module ActiveRedis
|
|
296
296
|
end
|
297
297
|
|
298
298
|
def set_field(field_name, options)
|
299
|
-
|
299
|
+
attributes_module.module_eval %Q{
|
300
300
|
def #{field_name}_object
|
301
301
|
Redis::Set.new(#{field_name}_redis_key)
|
302
302
|
end
|
303
303
|
|
304
|
-
def #{field_name}
|
304
|
+
def #{field_name}_val
|
305
305
|
@attributes[:#{field_name}] ||= begin
|
306
306
|
ActiveRedis::DirtyObjects::Array.new(#{field_name}_object.members)
|
307
307
|
end
|
@@ -329,12 +329,12 @@ module ActiveRedis
|
|
329
329
|
end
|
330
330
|
|
331
331
|
def sorted_set_field(field_name, options)
|
332
|
-
|
332
|
+
attributes_module.module_eval %Q{
|
333
333
|
def #{field_name}_object
|
334
334
|
Redis::SortedSet.new(#{field_name}_redis_key)
|
335
335
|
end
|
336
336
|
|
337
|
-
def #{field_name}
|
337
|
+
def #{field_name}_val
|
338
338
|
@attributes[:#{field_name}] ||= begin
|
339
339
|
ActiveRedis::DirtyObjects::SortedSet.new(#{field_name}_object.members)
|
340
340
|
end
|
@@ -358,12 +358,12 @@ module ActiveRedis
|
|
358
358
|
end
|
359
359
|
|
360
360
|
def hash_field(field_name, options)
|
361
|
-
|
361
|
+
attributes_module.module_eval %Q{
|
362
362
|
def #{field_name}_hash_set
|
363
363
|
Redis::HashKey.new(#{field_name}_redis_key)
|
364
364
|
end
|
365
365
|
|
366
|
-
def #{field_name}
|
366
|
+
def #{field_name}_val
|
367
367
|
@attributes[:#{field_name}] ||= begin
|
368
368
|
ActiveRedis::DirtyObjects::Hash[#{field_name}_hash_set.all]
|
369
369
|
end
|
@@ -388,8 +388,8 @@ module ActiveRedis
|
|
388
388
|
|
389
389
|
def date_field(field_name, options)
|
390
390
|
string_field(field_name, options)
|
391
|
-
|
392
|
-
def #{field_name}
|
391
|
+
attributes_module.module_eval %Q{
|
392
|
+
def #{field_name}_val
|
393
393
|
@attributes[:#{field_name}] ||= begin
|
394
394
|
value = #{field_name}_object.value
|
395
395
|
if value.blank?
|
@@ -416,8 +416,8 @@ module ActiveRedis
|
|
416
416
|
|
417
417
|
def time_field(field_name, options)
|
418
418
|
string_field(field_name, options)
|
419
|
-
|
420
|
-
def #{field_name}
|
419
|
+
attributes_module.module_eval %Q{
|
420
|
+
def #{field_name}_val
|
421
421
|
@attributes[:#{field_name}] ||= begin
|
422
422
|
value = #{field_name}_object.value
|
423
423
|
if value.blank?
|
data/lib/active_redis/version.rb
CHANGED
data/lib/active_redis_orm.rb
CHANGED
@@ -67,9 +67,13 @@ module ActiveRedis
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
def attribute(name)
|
71
|
+
public_send("#{name}_val")
|
72
|
+
end
|
73
|
+
|
70
74
|
class << self
|
71
75
|
include ActiveRedis::Attributes
|
72
|
-
attr_accessor :attribute_definitions
|
76
|
+
attr_accessor :attribute_definitions, :attributes_module
|
73
77
|
|
74
78
|
def find(id)
|
75
79
|
new(id)
|
@@ -116,6 +120,8 @@ module ActiveRedis
|
|
116
120
|
end
|
117
121
|
end
|
118
122
|
end
|
123
|
+
klass.attributes_module = Module.new
|
124
|
+
klass.send(:include, klass.attributes_module)
|
119
125
|
end
|
120
126
|
end
|
121
127
|
end
|
@@ -334,4 +334,19 @@ describe ActiveRedis do
|
|
334
334
|
end
|
335
335
|
end
|
336
336
|
|
337
|
+
context "super" do
|
338
|
+
class ARWithSuper < ActiveRedis::Base
|
339
|
+
field :wagamama
|
340
|
+
|
341
|
+
def wagamama
|
342
|
+
"#{super}!"
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
it "allows super to be called on attribute definitions" do
|
347
|
+
object = ARWithSuper.create(wagamama: "bar")
|
348
|
+
object.wagamama.should == "bar!"
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
337
352
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_redis_orm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Caspy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/active_redis/timestamps.rb
|
135
135
|
- lib/active_redis/version.rb
|
136
136
|
- lib/active_redis_orm.rb
|
137
|
+
- spec/lib/active_redis/nil_object_spec.rb
|
137
138
|
- spec/lib/active_redis/validation_spec.rb
|
138
139
|
- spec/lib/active_redis_spec.rb
|
139
140
|
- spec/lib/attributes_spec.rb
|
@@ -162,6 +163,7 @@ signing_key:
|
|
162
163
|
specification_version: 4
|
163
164
|
summary: ActiveRedis is an ORM for redis written in Ruby.
|
164
165
|
test_files:
|
166
|
+
- spec/lib/active_redis/nil_object_spec.rb
|
165
167
|
- spec/lib/active_redis/validation_spec.rb
|
166
168
|
- spec/lib/active_redis_spec.rb
|
167
169
|
- spec/lib/attributes_spec.rb
|