active_redis_orm 0.1.1 → 0.1.2
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/all_list.rb +2 -2
- data/lib/active_redis/attributes.rb +14 -14
- data/lib/active_redis/save.rb +1 -1
- data/lib/active_redis/version.rb +1 -1
- data/lib/active_redis_orm.rb +5 -1
- data/spec/lib/active_redis_spec.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69575da090b72886a83b27078d14b461c6750d5a
|
4
|
+
data.tar.gz: fd66ae1837b07736e6e93d89877a28cfa7cabbab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f675563efa18c94e2e3e698d08f102ca213c4dafd1f22bff7a95fbbcd433952e756583b85423c3048a54167a9105aedf6fb4206b7b36ad43e9b5057e4afa31be
|
7
|
+
data.tar.gz: b98a86c0b724064805350d80598aeb8af7c958598765e77308d8b816ea0df8a6f1baf1f9c8f94c029c2badfc28ef376d51b11846c720674b9e40230926d63117
|
@@ -45,11 +45,11 @@ module ActiveRedis
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def add
|
48
|
-
|
48
|
+
@object.class.redis.zadd(key, Time.now.to_f, @object.id) if should_add?
|
49
49
|
end
|
50
50
|
|
51
51
|
def remove
|
52
|
-
|
52
|
+
@object.class.redis.zrem(key, @object.id)
|
53
53
|
end
|
54
54
|
|
55
55
|
def key
|
@@ -24,7 +24,7 @@ module ActiveRedis
|
|
24
24
|
def expire_field(field_name)
|
25
25
|
expires_in = self.class.attribute_options[field_name.to_sym][:expires_in]
|
26
26
|
if expires_in.to_i > 0
|
27
|
-
|
27
|
+
self.class.redis.expire(send("#{field_name}_redis_key"), expires_in.to_i)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -51,7 +51,7 @@ module ActiveRedis
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def destroy_#{field_name}
|
54
|
-
Redis::Value.new(#{field_name}_redis_key).delete
|
54
|
+
Redis::Value.new(#{field_name}_redis_key, self.class.redis).delete
|
55
55
|
end
|
56
56
|
}
|
57
57
|
if options[:finder_field]
|
@@ -90,7 +90,7 @@ module ActiveRedis
|
|
90
90
|
def string_field(field_name, options)
|
91
91
|
attributes_module.module_eval %Q{
|
92
92
|
def #{field_name}_object
|
93
|
-
Redis::Value.new(#{field_name}_redis_key)
|
93
|
+
Redis::Value.new(#{field_name}_redis_key, self.class.redis)
|
94
94
|
end
|
95
95
|
|
96
96
|
def #{field_name}_val
|
@@ -121,7 +121,7 @@ module ActiveRedis
|
|
121
121
|
def integer_field(field_name, options)
|
122
122
|
attributes_module.module_eval %Q{
|
123
123
|
def #{field_name}_object
|
124
|
-
Redis::Value.new(#{field_name}_redis_key)
|
124
|
+
Redis::Value.new(#{field_name}_redis_key, self.class.redis)
|
125
125
|
end
|
126
126
|
|
127
127
|
def #{field_name}_val
|
@@ -155,7 +155,7 @@ module ActiveRedis
|
|
155
155
|
def float_field(field_name, options)
|
156
156
|
attributes_module.module_eval %Q{
|
157
157
|
def #{field_name}_object
|
158
|
-
Redis::Value.new(#{field_name}_redis_key)
|
158
|
+
Redis::Value.new(#{field_name}_redis_key, self.class.redis)
|
159
159
|
end
|
160
160
|
|
161
161
|
def #{field_name}_val
|
@@ -189,7 +189,7 @@ module ActiveRedis
|
|
189
189
|
def boolean_field(field_name, options)
|
190
190
|
attributes_module.module_eval %Q{
|
191
191
|
def #{field_name}_object
|
192
|
-
Redis::Value.new(#{field_name}_redis_key)
|
192
|
+
Redis::Value.new(#{field_name}_redis_key, self.class.redis)
|
193
193
|
end
|
194
194
|
|
195
195
|
def #{field_name}_val
|
@@ -226,7 +226,7 @@ module ActiveRedis
|
|
226
226
|
def counter_field(field_name, options)
|
227
227
|
attributes_module.module_eval %Q{
|
228
228
|
def #{field_name}_object
|
229
|
-
Redis::Counter.new(#{field_name}_redis_key)
|
229
|
+
Redis::Counter.new(#{field_name}_redis_key, self.class.redis)
|
230
230
|
end
|
231
231
|
|
232
232
|
def #{field_name}_val
|
@@ -256,7 +256,7 @@ module ActiveRedis
|
|
256
256
|
def list_field(field_name, options)
|
257
257
|
attributes_module.module_eval %Q{
|
258
258
|
def #{field_name}_object
|
259
|
-
Redis::List.new(#{field_name}_redis_key)
|
259
|
+
Redis::List.new(#{field_name}_redis_key, self.class.redis)
|
260
260
|
end
|
261
261
|
|
262
262
|
def #{field_name}_val
|
@@ -298,7 +298,7 @@ module ActiveRedis
|
|
298
298
|
def set_field(field_name, options)
|
299
299
|
attributes_module.module_eval %Q{
|
300
300
|
def #{field_name}_object
|
301
|
-
Redis::Set.new(#{field_name}_redis_key)
|
301
|
+
Redis::Set.new(#{field_name}_redis_key, self.class.redis)
|
302
302
|
end
|
303
303
|
|
304
304
|
def #{field_name}_val
|
@@ -331,7 +331,7 @@ module ActiveRedis
|
|
331
331
|
def sorted_set_field(field_name, options)
|
332
332
|
attributes_module.module_eval %Q{
|
333
333
|
def #{field_name}_object
|
334
|
-
Redis::SortedSet.new(#{field_name}_redis_key)
|
334
|
+
Redis::SortedSet.new(#{field_name}_redis_key, self.class.redis)
|
335
335
|
end
|
336
336
|
|
337
337
|
def #{field_name}_val
|
@@ -360,7 +360,7 @@ module ActiveRedis
|
|
360
360
|
def hash_field(field_name, options)
|
361
361
|
attributes_module.module_eval %Q{
|
362
362
|
def #{field_name}_hash_set
|
363
|
-
Redis::HashKey.new(#{field_name}_redis_key)
|
363
|
+
Redis::HashKey.new(#{field_name}_redis_key, self.class.redis)
|
364
364
|
end
|
365
365
|
|
366
366
|
def #{field_name}_val
|
@@ -438,14 +438,14 @@ module ActiveRedis
|
|
438
438
|
def finder_field(field_name, options)
|
439
439
|
before_save do
|
440
440
|
if send("#{field_name}_changed?")
|
441
|
-
|
442
|
-
|
441
|
+
self.class.redis.del(self.class.finder_key(field_name, send("#{field_name}_was")))
|
442
|
+
self.class.redis.set(self.class.finder_key(field_name, send(field_name)), id)
|
443
443
|
end
|
444
444
|
end
|
445
445
|
|
446
446
|
class_eval %Q{
|
447
447
|
def self.find_by_#{field_name}(value)
|
448
|
-
id =
|
448
|
+
id = redis.get(finder_key(:#{field_name}, value))
|
449
449
|
if id.present?
|
450
450
|
self.find(id)
|
451
451
|
else
|
data/lib/active_redis/save.rb
CHANGED
data/lib/active_redis/version.rb
CHANGED
data/lib/active_redis_orm.rb
CHANGED
@@ -73,7 +73,7 @@ module ActiveRedis
|
|
73
73
|
|
74
74
|
class << self
|
75
75
|
include ActiveRedis::Attributes
|
76
|
-
attr_accessor :attribute_definitions, :attributes_module
|
76
|
+
attr_accessor :attribute_definitions, :attributes_module, :redis
|
77
77
|
|
78
78
|
def find(id)
|
79
79
|
new(id)
|
@@ -112,6 +112,10 @@ module ActiveRedis
|
|
112
112
|
attribute_definitions
|
113
113
|
end
|
114
114
|
|
115
|
+
def redis
|
116
|
+
@redis ||= ::ActiveRedis.redis
|
117
|
+
end
|
118
|
+
|
115
119
|
def inherited(klass)
|
116
120
|
class << klass
|
117
121
|
self.class_eval do
|
@@ -357,4 +357,24 @@ describe ActiveRedis do
|
|
357
357
|
end
|
358
358
|
end
|
359
359
|
|
360
|
+
context "different redis connections" do
|
361
|
+
class DifferentConnection < ActiveRedis::Base
|
362
|
+
self.redis = Redis.new(db: 1)
|
363
|
+
field :foo
|
364
|
+
end
|
365
|
+
|
366
|
+
let(:con) {DifferentConnection.create(foo: "bar")}
|
367
|
+
|
368
|
+
it "writes to a different connection" do
|
369
|
+
con.reload!
|
370
|
+
con.foo.should == "bar"
|
371
|
+
ActiveRedis.redis.get(con.foo_object.key).should be_blank
|
372
|
+
DifferentConnection.redis.get(con.foo_object.key).should == "bar"
|
373
|
+
end
|
374
|
+
|
375
|
+
it "also sets the redis connection for the redis object" do
|
376
|
+
con.foo_object.value.should == "bar"
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
360
380
|
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.1.
|
4
|
+
version: 0.1.2
|
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-09-
|
11
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|