redis-persistence 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/article.rb +2 -2
- data/lib/redis/persistence.rb +3 -1
- data/lib/redis/persistence/version.rb +1 -1
- data/test/models.rb +4 -3
- data/test/redis_persistence_test.rb +10 -2
- metadata +19 -19
data/examples/article.rb
CHANGED
@@ -64,7 +64,7 @@ article.comments << Comment.new(:nick => 'h4x0r', :body => 'WHY U NO USE BBS?')
|
|
64
64
|
p article.comments.size
|
65
65
|
# => 2
|
66
66
|
|
67
|
-
p article.save
|
67
|
+
p article.save(families: 'comments')
|
68
68
|
# => <Article: {"id"=>3, ... "comments"=>[{:nick=>"4chan", :body=>"WHY U NO QUIT?"}]}>
|
69
69
|
|
70
70
|
article = Article.find(3)
|
@@ -73,7 +73,7 @@ p article.comments
|
|
73
73
|
|
74
74
|
article = Article.find(3, :families => 'comments')
|
75
75
|
p article.comments
|
76
|
-
# => [#<Comment
|
76
|
+
# => [#<Comment @attributes={"nick"=>"4chan", "body"=>"WHY U NO QUIT?"}>, ...]
|
77
77
|
|
78
78
|
p article.comments.first.nick
|
79
79
|
# => "4chan"
|
data/lib/redis/persistence.rb
CHANGED
@@ -294,7 +294,9 @@ class Redis
|
|
294
294
|
def save(options={})
|
295
295
|
run_callbacks :save do
|
296
296
|
self.id ||= self.class.__next_id
|
297
|
-
families = options[:families] == 'all'
|
297
|
+
families = if options[:families] == 'all'; self.class.property_families.keys
|
298
|
+
else; self.__loaded_families | Array(options[:families])
|
299
|
+
end
|
298
300
|
params = families.map do |family|
|
299
301
|
[family.to_s, self.to_json(:only => self.class.property_families[family.to_sym])]
|
300
302
|
end.flatten
|
data/test/models.rb
CHANGED
@@ -94,10 +94,11 @@ class ModelWithFamily
|
|
94
94
|
|
95
95
|
property :name
|
96
96
|
|
97
|
-
property :views, :family
|
98
|
-
property :visits, :family
|
97
|
+
property :views, :family => 'counters'
|
98
|
+
property :visits, :family => 'counters'
|
99
|
+
property :tags, :family => 'tags', :default => []
|
99
100
|
|
100
|
-
property :lang, :family
|
101
|
+
property :lang, :family => 'meta'
|
101
102
|
end
|
102
103
|
|
103
104
|
class ModelWithCastingInFamily
|
@@ -269,7 +269,7 @@ class RedisPersistenceTest < ActiveSupport::TestCase
|
|
269
269
|
assert_nil m.views
|
270
270
|
|
271
271
|
m = ModelWithFamily.find(1, families: 'all')
|
272
|
-
assert_equal
|
272
|
+
assert_equal 4, m.__loaded_families.size
|
273
273
|
assert_equal 'One', m.name
|
274
274
|
assert_equal 10, m.views
|
275
275
|
assert_equal 'en', m.lang
|
@@ -334,6 +334,14 @@ class RedisPersistenceTest < ActiveSupport::TestCase
|
|
334
334
|
assert in_redis.keys.size < keys_count, 'Key not removed from Redis?'
|
335
335
|
end
|
336
336
|
|
337
|
+
should "save specific family" do
|
338
|
+
m = ModelWithFamily.new name: 'Test'
|
339
|
+
m.tags << 'a'
|
340
|
+
assert m.save(families: 'tags')
|
341
|
+
|
342
|
+
assert_equal 'a', ModelWithFamily.find(1, families: 'tags').tags.first
|
343
|
+
end
|
344
|
+
|
337
345
|
should "save all families" do
|
338
346
|
m = ModelWithFamily.new name: 'Test'
|
339
347
|
assert m.save
|
@@ -344,7 +352,7 @@ class RedisPersistenceTest < ActiveSupport::TestCase
|
|
344
352
|
assert in_redis.keys.size > 0, 'Key not saved into Redis?'
|
345
353
|
|
346
354
|
# ["default", "counters", "meta"]
|
347
|
-
assert_equal
|
355
|
+
assert_equal 4, in_redis.hkeys("model_with_families:2").size
|
348
356
|
end
|
349
357
|
|
350
358
|
should "update attributes" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-persistence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2011-11-20 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
17
|
-
requirement: &
|
17
|
+
requirement: &70189836581020 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '3.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70189836581020
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: multi_json
|
28
|
-
requirement: &
|
28
|
+
requirement: &70189836580520 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70189836580520
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: redis
|
39
|
-
requirement: &
|
39
|
+
requirement: &70189836580060 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 2.2.2
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70189836580060
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: hashr
|
50
|
-
requirement: &
|
50
|
+
requirement: &70189836579600 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 0.0.16
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70189836579600
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: bundler
|
61
|
-
requirement: &
|
61
|
+
requirement: &70189836579140 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '1.0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70189836579140
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: yajl-ruby
|
72
|
-
requirement: &
|
72
|
+
requirement: &70189836578680 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: 0.8.0
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70189836578680
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: shoulda
|
83
|
-
requirement: &
|
83
|
+
requirement: &70189836578300 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *70189836578300
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: mocha
|
94
|
-
requirement: &
|
94
|
+
requirement: &70189836577840 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ! '>='
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: '0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *70189836577840
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: turn
|
105
|
-
requirement: &
|
105
|
+
requirement: &70189836577420 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ! '>='
|
@@ -110,7 +110,7 @@ dependencies:
|
|
110
110
|
version: '0'
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *70189836577420
|
114
114
|
description: Simple ActiveModel-compatible persistence layer in Redis
|
115
115
|
email:
|
116
116
|
- karmi@karmi.cz
|