redis_orm 0.2 → 0.3
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.
- data/CHANGELOG +5 -0
- data/README.md +35 -1
- data/Rakefile +1 -1
- data/lib/redis_orm/associations/belongs_to.rb +19 -16
- data/lib/redis_orm/associations/has_many.rb +17 -4
- data/lib/redis_orm/associations/has_many_proxy.rb +13 -2
- data/lib/redis_orm/associations/has_one.rb +15 -10
- data/lib/redis_orm/redis_orm.rb +23 -13
- data/redis_orm.gemspec +2 -2
- data/test/associations_test.rb +61 -5
- data/test/options_test.rb +19 -8
- metadata +10 -10
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
v0.3 [06-06-2011]
|
2
|
+
* fixed #find functionality both for model itself and for has_many proxy
|
3
|
+
* made sure ORM correctly resets associations when nil/[] provided
|
4
|
+
* improved documentation, test for has_many proxy methods :+= and :<< added
|
5
|
+
|
1
6
|
v0.2 [04-06-2011]
|
2
7
|
* added polymorphic association
|
3
8
|
* added *timestamps* declaration for the model
|
data/README.md
CHANGED
@@ -87,7 +87,15 @@ For example we associate 2 photos with the album
|
|
87
87
|
@album.photos << @photo1
|
88
88
|
```
|
89
89
|
|
90
|
-
To extract all or part of the associated records
|
90
|
+
To extract all or part of the associated records you could use 3 options for now (#find is an alias for #all in has_many proxy):
|
91
|
+
|
92
|
+
* :limit
|
93
|
+
|
94
|
+
* :offset
|
95
|
+
|
96
|
+
* :order
|
97
|
+
|
98
|
+
Either :desc or :asc (default), since records are stored with Time.now.to_f scores, be default they could be fetched only in that (or reversed) order. To store them in different order you should *zadd* record's id to some other sorted list manually.
|
91
99
|
|
92
100
|
```ruby
|
93
101
|
@album.photos.all(:limit => 0, :offset => 0).should == []
|
@@ -295,6 +303,32 @@ All associations supports following options:
|
|
295
303
|
|
296
304
|
Symbol could be either :destroy or :nullify (default value)
|
297
305
|
|
306
|
+
### Clearing/reseting associations
|
307
|
+
|
308
|
+
You could clear/reset associations by assigning appropriately nil/[] to it:
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
# has_many association
|
312
|
+
@article.comments << [@comment1, @comment2]
|
313
|
+
@article.comments.count # => 2
|
314
|
+
@comment1.article # => @article
|
315
|
+
|
316
|
+
# clear
|
317
|
+
@article.comments = []
|
318
|
+
@article.comments.count # => 0
|
319
|
+
@comment1.article # => nil
|
320
|
+
|
321
|
+
# belongs_to (same for has_one)
|
322
|
+
@article.comments << [@comment1, @comment2]
|
323
|
+
@article.comments.count # => 2
|
324
|
+
@comment1.article # => @article
|
325
|
+
|
326
|
+
# clear
|
327
|
+
@comment1.article = nil
|
328
|
+
@article.comments.count # => 1
|
329
|
+
@comment1.article # => nil
|
330
|
+
```
|
331
|
+
|
298
332
|
For more examples please check test/associations_test.rb and test/polymorphic_test.rb
|
299
333
|
|
300
334
|
## Validation
|
data/Rakefile
CHANGED
@@ -34,34 +34,37 @@ module RedisOrm
|
|
34
34
|
# look = Look.create :title => 'test'
|
35
35
|
# look.user = User.find(1) => look:23:user => 1
|
36
36
|
define_method "#{foreign_model_name}=" do |assoc_with_record|
|
37
|
-
|
37
|
+
# we need to store this to clear old association later
|
38
|
+
old_assoc = self.send(foreign_model_name)
|
38
39
|
|
39
40
|
if options[:polymorphic]
|
40
|
-
# we need to store this to clear old association later
|
41
|
-
old_assoc = self.send(foreign_model_name)
|
42
41
|
$redis.set("#{model_name}:#{id}:#{foreign_model_name}_type", assoc_with_record.model_name)
|
43
42
|
$redis.set("#{model_name}:#{id}:#{foreign_model_name}_id", assoc_with_record.id)
|
44
43
|
else
|
45
|
-
if assoc_with_record.
|
44
|
+
if assoc_with_record.nil?
|
45
|
+
$redis.del("#{model_name}:#{id}:#{foreign_model_name}")
|
46
|
+
elsif assoc_with_record.model_name == foreign_model.to_s
|
46
47
|
$redis.set("#{model_name}:#{id}:#{foreign_model_name}", assoc_with_record.id)
|
47
48
|
else
|
48
49
|
raise TypeMismatchError
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
#
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
if assoc_with_record.nil?
|
54
|
+
# remove old assoc
|
55
|
+
$redis.zrem("#{old_assoc.model_name}:#{old_assoc.id}:#{model_name.to_s.pluralize}", self.id) if old_assoc
|
56
|
+
else
|
57
|
+
# check whether *assoc_with_record* object has *has_many* declaration and TODO it states *self.model_name* in plural and there is no record yet from the *assoc_with_record*'s side (in order not to provoke recursion)
|
58
|
+
if class_associations[assoc_with_record.model_name].detect{|h| h[:type] == :has_many && h[:foreign_models] == model_name.pluralize.to_sym} && !$redis.zrank("#{assoc_with_record.model_name}:#{assoc_with_record.id}:#{model_name.pluralize}", self.id)
|
59
|
+
# remove old assoc
|
60
|
+
$redis.zrem("#{old_assoc.model_name}:#{old_assoc.id}:#{model_name.to_s.pluralize}", self.id) if old_assoc
|
61
|
+
assoc_with_record.send(model_name.pluralize.to_sym).send(:"<<", self)
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
# check whether *assoc_with_record* object has *has_one* declaration and TODO it states *self.model_name* and there is no record yet from the *assoc_with_record*'s side (in order not to provoke recursion)
|
64
|
+
elsif class_associations[assoc_with_record.model_name].detect{|h| h[:type] == :has_one && h[:foreign_model] == model_name.to_sym} && assoc_with_record.send(model_name.to_sym).nil?
|
65
|
+
# old association is being rewritten here automatically so we don't have to worry about it
|
66
|
+
assoc_with_record.send("#{model_name}=", self)
|
67
|
+
end
|
65
68
|
end
|
66
69
|
end
|
67
70
|
end
|
@@ -23,10 +23,22 @@ module RedisOrm
|
|
23
23
|
define_method "#{foreign_models_name}=" do |records|
|
24
24
|
if !options[:as]
|
25
25
|
# clear old assocs from related models side
|
26
|
-
self.send(foreign_models).to_a
|
27
|
-
|
26
|
+
old_records = self.send(foreign_models).to_a
|
27
|
+
if !old_records.empty?
|
28
|
+
# cache here which association with current model have old record's model
|
29
|
+
has_many_assoc = old_records[0].get_associations.detect{|h| h[:type] == :has_many && h[:foreign_models] == model_name.pluralize.to_sym}
|
30
|
+
|
31
|
+
has_one_or_belongs_to_assoc = old_records[0].get_associations.detect{|h| [:has_one, :belongs_to].include?(h[:type]) && h[:foreign_model] == model_name.to_sym}
|
32
|
+
|
33
|
+
old_records.each do |record|
|
34
|
+
if has_many_assoc
|
35
|
+
$redis.zrem "#{record.model_name}:#{record.id}:#{model_name.pluralize}", id
|
36
|
+
elsif has_one_or_belongs_to_assoc
|
37
|
+
$redis.del "#{record.model_name}:#{record.id}:#{model_name}"
|
38
|
+
end
|
39
|
+
end
|
28
40
|
end
|
29
|
-
|
41
|
+
|
30
42
|
# clear old assocs from this model side
|
31
43
|
$redis.zremrangebyscore "#{model_name}:#{id}:#{foreign_models}", 0, Time.now.to_f
|
32
44
|
end
|
@@ -42,7 +54,8 @@ module RedisOrm
|
|
42
54
|
if class_associations[record.model_name].detect{|h| h[:type] == :has_many && h[:foreign_models] == model_name.pluralize.to_sym} #&& !$redis.zrank("#{record.model_name}:#{record.id}:#{model_name.pluralize}", id)#record.model_name.to_s.camelize.constantize.find(id).nil?
|
43
55
|
$redis.zadd("#{record.model_name}:#{record.id}:#{model_name.pluralize}", Time.now.to_f, id)
|
44
56
|
# check whether *record* object has *has_one* declaration and TODO it states *self.model_name*
|
45
|
-
elsif record.get_associations.detect{|h| [:has_one, :belongs_to].include?(h[:type]) && h[:foreign_model] == model_name.to_sym}
|
57
|
+
elsif record.get_associations.detect{|h| [:has_one, :belongs_to].include?(h[:type]) && h[:foreign_model] == model_name.to_sym}
|
58
|
+
# overwrite assoc anyway so we don't need to check record.send(model_name.to_sym).nil? here
|
46
59
|
$redis.set("#{record.model_name}:#{record.id}:#{model_name}", id)
|
47
60
|
end
|
48
61
|
end
|
@@ -19,6 +19,11 @@ module RedisOrm
|
|
19
19
|
fetch if !@fetched
|
20
20
|
@records[index]
|
21
21
|
end
|
22
|
+
|
23
|
+
def to_a
|
24
|
+
fetch if !@fetched
|
25
|
+
@records
|
26
|
+
end
|
22
27
|
|
23
28
|
# user = User.find(1)
|
24
29
|
# user.avatars << Avatar.find(23) => user:1:avatars => [23]
|
@@ -55,10 +60,13 @@ module RedisOrm
|
|
55
60
|
end
|
56
61
|
end
|
57
62
|
end
|
63
|
+
|
64
|
+
# return *self* here so calls could be chained
|
65
|
+
self
|
58
66
|
end
|
59
67
|
|
60
68
|
def all(options = {})
|
61
|
-
if options[:limit] || options[:offset] || options[:order]
|
69
|
+
if options.is_a?(Hash) && (options[:limit] || options[:offset] || options[:order])
|
62
70
|
limit = if options[:limit] && options[:offset]
|
63
71
|
[options[:offset].to_i, options[:limit].to_i]
|
64
72
|
elsif options[:limit]
|
@@ -90,7 +98,10 @@ module RedisOrm
|
|
90
98
|
elsif token == :all
|
91
99
|
all(options)
|
92
100
|
elsif token == :first
|
93
|
-
all(options.merge({:limit => 1}))
|
101
|
+
all(options.merge({:limit => 1}))[0]
|
102
|
+
elsif token == :last
|
103
|
+
reversed = options[:order] == 'asc' ? 'desc' : 'asc'
|
104
|
+
all(options.merge({:limit => 1, :order => reversed}))[0]
|
94
105
|
end
|
95
106
|
end
|
96
107
|
|
@@ -25,23 +25,28 @@ module RedisOrm
|
|
25
25
|
# we need to store this to clear old associations later
|
26
26
|
old_assoc = self.send(foreign_model_name)
|
27
27
|
|
28
|
-
if assoc_with_record.
|
28
|
+
if assoc_with_record.nil?
|
29
|
+
$redis.del("#{model_name}:#{id}:#{foreign_model_name}")
|
30
|
+
elsif assoc_with_record.model_name == foreign_model.to_s
|
29
31
|
$redis.set("#{model_name}:#{id}:#{foreign_model_name}", assoc_with_record.id)
|
30
32
|
else
|
31
33
|
raise TypeMismatchError
|
32
34
|
end
|
33
35
|
|
34
|
-
|
35
|
-
if class_associations[assoc_with_record.model_name].detect{|h| [:belongs_to, :has_one].include?(h[:type]) && h[:foreign_model] == model_name.to_sym} && assoc_with_record.send(model_name.to_sym).nil?
|
36
|
-
# old association is being rewritten here automatically so we don't have to worry about it
|
37
|
-
assoc_with_record.send("#{model_name}=", self)
|
38
|
-
elsif class_associations[assoc_with_record.model_name].detect{|h| :has_many == h[:type] && h[:foreign_models] == model_name.to_s.pluralize.to_sym} && !$redis.zrank("#{assoc_with_record.model_name}:#{assoc_with_record.id}:#{model_name.pluralize}", self.id)
|
36
|
+
if assoc_with_record.nil?
|
39
37
|
# remove old assoc
|
40
|
-
if old_assoc
|
41
|
-
|
38
|
+
$redis.zrem("#{old_assoc.model_name}:#{old_assoc.id}:#{model_name.to_s.pluralize}", id) if old_assoc
|
39
|
+
else
|
40
|
+
# check whether *assoc_with_record* object has *belongs_to* declaration and TODO it states *self.model_name* and there is no record yet from the *assoc_with_record*'s side (in order not to provoke recursion)
|
41
|
+
if class_associations[assoc_with_record.model_name].detect{|h| [:belongs_to, :has_one].include?(h[:type]) && h[:foreign_model] == model_name.to_sym} && assoc_with_record.send(model_name.to_sym).nil?
|
42
|
+
# old association is being rewritten here automatically so we don't have to worry about it
|
43
|
+
assoc_with_record.send("#{model_name}=", self)
|
44
|
+
elsif class_associations[assoc_with_record.model_name].detect{|h| :has_many == h[:type] && h[:foreign_models] == model_name.to_s.pluralize.to_sym} && !$redis.zrank("#{assoc_with_record.model_name}:#{assoc_with_record.id}:#{model_name.pluralize}", self.id)
|
45
|
+
# remove old assoc
|
46
|
+
$redis.zrem("#{old_assoc.model_name}:#{old_assoc.id}:#{model_name.to_s.pluralize}", id) if old_assoc
|
47
|
+
# create/add new ones
|
48
|
+
assoc_with_record.send(model_name.pluralize.to_sym).send(:"<<", self)
|
42
49
|
end
|
43
|
-
# create/add new ones
|
44
|
-
assoc_with_record.send(model_name.pluralize.to_sym).send(:"<<", self)
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
data/lib/redis_orm/redis_orm.rb
CHANGED
@@ -138,25 +138,35 @@ module RedisOrm
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
def find(
|
142
|
-
if
|
143
|
-
|
144
|
-
|
145
|
-
return [] if ids.empty?
|
146
|
-
ids.inject([]) do |array, id|
|
141
|
+
def find(*args)
|
142
|
+
if args.first.is_a?(Array)
|
143
|
+
return [] if args.first.empty?
|
144
|
+
args.first.inject([]) do |array, id|
|
147
145
|
record = $redis.hgetall "#{model_name}:#{id}"
|
148
146
|
if record && !record.empty?
|
149
147
|
array << new(record, id, true)
|
150
148
|
end
|
151
149
|
end
|
152
150
|
else
|
153
|
-
return nil if
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
151
|
+
return nil if args.empty? || args.first.nil?
|
152
|
+
case first = args.shift
|
153
|
+
when :all
|
154
|
+
options = args.last
|
155
|
+
return nil if !options.is_a?(Hash)
|
156
|
+
all(options)
|
157
|
+
when :first
|
158
|
+
options = args.last
|
159
|
+
return nil if !options.is_a?(Hash)
|
160
|
+
all(options.merge({:limit => 1}))[0]
|
161
|
+
when :last
|
162
|
+
options = args.last
|
163
|
+
return nil if !options.is_a?(Hash)
|
164
|
+
reversed = options[:order] == 'asc' ? 'desc' : 'asc'
|
165
|
+
all(options.merge({:limit => 1, :order => reversed}))[0]
|
166
|
+
else
|
167
|
+
id = first
|
168
|
+
record = $redis.hgetall "#{model_name}:#{id}"
|
169
|
+
record && record.empty? ? nil : new(record, id, true)
|
160
170
|
end
|
161
171
|
end
|
162
172
|
end
|
data/redis_orm.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{redis_orm}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Dmitrii Samoilov"]
|
9
|
-
s.date = %q{2011-06-
|
9
|
+
s.date = %q{2011-06-06}
|
10
10
|
s.description = %q{ORM for Redis advanced key-value storage}
|
11
11
|
s.email = %q{germaninthetown@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "lib/redis_orm.rb", "lib/redis_orm/active_model_behavior.rb", "lib/redis_orm/associations/belongs_to.rb", "lib/redis_orm/associations/has_many.rb", "lib/redis_orm/associations/has_many_proxy.rb", "lib/redis_orm/associations/has_one.rb", "lib/redis_orm/redis_orm.rb"]
|
data/test/associations_test.rb
CHANGED
@@ -41,7 +41,7 @@ describe "check associations" do
|
|
41
41
|
path_to_socket = File.dirname(File.expand_path(__FILE__)) + "/../redis.sock"
|
42
42
|
$redis = Redis.new(:host => 'localhost', :path => path_to_socket)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
before(:each) do
|
46
46
|
$redis.flushall if $redis
|
47
47
|
@article = Article.new
|
@@ -84,10 +84,44 @@ describe "check associations" do
|
|
84
84
|
@comment2.article.id.should == @article.id
|
85
85
|
@article.comments.count.should == 2
|
86
86
|
@article.comments[0].id.should == @comment2.id
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should correctly resets associations when nil/[] provided" do
|
90
|
+
# from has_many proxy side
|
91
|
+
@article.comments << [@comment1, @comment2]
|
92
|
+
@article.comments.count.should == 2
|
93
|
+
@comment1.article.id.should == @article.id
|
94
|
+
@comment2.article.id.should == @article.id
|
87
95
|
|
88
|
-
|
89
|
-
|
90
|
-
|
96
|
+
# clear
|
97
|
+
@article.comments = []
|
98
|
+
@article.comments.count.should == 0
|
99
|
+
@comment1.article.should == nil
|
100
|
+
@comment2.article.should == nil
|
101
|
+
|
102
|
+
# from belongs_to side
|
103
|
+
@article.comments << [@comment1, @comment2]
|
104
|
+
@article.comments.count.should == 2
|
105
|
+
@comment1.article.id.should == @article.id
|
106
|
+
|
107
|
+
# clear
|
108
|
+
@comment1.article = nil
|
109
|
+
@article.comments.count.should == 1
|
110
|
+
@comment1.article.should == nil
|
111
|
+
|
112
|
+
# from has_one side
|
113
|
+
profile = Profile.create :title => "test"
|
114
|
+
chicago = City.create :name => "Chicago"
|
115
|
+
|
116
|
+
profile.city = chicago
|
117
|
+
profile.city.name.should == "Chicago"
|
118
|
+
chicago.profiles.count.should == 1
|
119
|
+
chicago.profiles[0].id.should == profile.id
|
120
|
+
|
121
|
+
# clear
|
122
|
+
profile.city = nil
|
123
|
+
profile.city.should == nil
|
124
|
+
chicago.profiles.count.should == 0
|
91
125
|
end
|
92
126
|
|
93
127
|
it "should return array" do
|
@@ -109,6 +143,28 @@ describe "check associations" do
|
|
109
143
|
@comment1.article.id.should == @comment2.article.id
|
110
144
|
end
|
111
145
|
|
146
|
+
it "should behave as active_record (proxy couldn't return records w/o #all call) += and << behave differently" do
|
147
|
+
@article.comments << @comment1 << @comment2
|
148
|
+
@article.comments.count.should == 2
|
149
|
+
|
150
|
+
comments = @article.comments
|
151
|
+
comments.count.should == 2
|
152
|
+
|
153
|
+
comments = []
|
154
|
+
comments += @article.comments
|
155
|
+
comments.count.should == 2
|
156
|
+
comments.collect{|c| c.id}.should include(@comment1.id)
|
157
|
+
comments.collect{|c| c.id}.should include(@comment2.id)
|
158
|
+
|
159
|
+
comments = []
|
160
|
+
comments << @article.comments.all
|
161
|
+
comments.flatten.count.should == 2
|
162
|
+
|
163
|
+
comments = []
|
164
|
+
comments << @article.comments
|
165
|
+
comments.count.should == 1
|
166
|
+
end
|
167
|
+
|
112
168
|
it "should return 1 comment when second was deleted" do
|
113
169
|
Comment.count.should == 2
|
114
170
|
@article.comments << [@comment1, @comment2]
|
@@ -150,7 +206,7 @@ describe "check associations" do
|
|
150
206
|
@article.comments.count.should == 1
|
151
207
|
@article.comments.first.id.should == @comment1.id
|
152
208
|
|
153
|
-
@comment1.article.id.should == @article.id
|
209
|
+
@comment1.article.id.should == @article.id
|
154
210
|
end
|
155
211
|
|
156
212
|
it "should correctly use many-to-many associations both with '=' and '<<' " do
|
data/test/options_test.rb
CHANGED
@@ -96,15 +96,18 @@ describe "test options" do
|
|
96
96
|
Photo.all(:order => "desc", :limit => 1, :offset => 1).map{|p| p.id}.should == [@photo1.id]
|
97
97
|
|
98
98
|
# testing #find method
|
99
|
-
Photo.find(:order => "asc").map{|p| p.id}.should == [@photo1.id, @photo2.id]
|
100
|
-
Photo.find(:order => "desc").map{|p| p.id}.should == [@photo2.id, @photo1.id]
|
99
|
+
Photo.find(:all, :order => "asc").map{|p| p.id}.should == [@photo1.id, @photo2.id]
|
100
|
+
Photo.find(:all, :order => "desc").map{|p| p.id}.should == [@photo2.id, @photo1.id]
|
101
101
|
|
102
|
-
Photo.find(:order => "asc", :limit => 1).map{|p| p.id}.should == [@photo1.id]
|
103
|
-
Photo.find(:order => "desc", :limit => 1).map{|p| p.id}.should == [@photo2.id]
|
102
|
+
Photo.find(:all, :order => "asc", :limit => 1).map{|p| p.id}.should == [@photo1.id]
|
103
|
+
Photo.find(:all, :order => "desc", :limit => 1).map{|p| p.id}.should == [@photo2.id]
|
104
104
|
|
105
|
-
Photo.find(:order => "asc", :limit => 1, :offset => 1).
|
106
|
-
Photo.find(:order => "desc", :limit => 1, :offset => 1).
|
105
|
+
Photo.find(:first, :order => "asc", :limit => 1, :offset => 1).id.should == @photo2.id
|
106
|
+
Photo.find(:first, :order => "desc", :limit => 1, :offset => 1).id.should == @photo1.id
|
107
107
|
|
108
|
+
Photo.find(:last, :order => "asc").id.should == @photo2.id
|
109
|
+
Photo.find(:last, :order => "desc").id.should == @photo1.id
|
110
|
+
|
108
111
|
@album.photos.count.should == 0
|
109
112
|
@album.photos.all(:limit => 2, :offset => 0).should == []
|
110
113
|
@album.photos << @photo2
|
@@ -119,8 +122,16 @@ describe "test options" do
|
|
119
122
|
|
120
123
|
@album.photos.find(:all, :order => "asc").map{|p| p.id}.should == [@photo2.id, @photo1.id]
|
121
124
|
@album.photos.find(:all, :order => "desc").map{|p| p.id}.should == [@photo1.id, @photo2.id]
|
122
|
-
|
123
|
-
@album.photos.find(:first, :order => "
|
125
|
+
|
126
|
+
@album.photos.find(:first, :order => "asc").id.should == @photo2.id
|
127
|
+
@album.photos.find(:first, :order => "desc").id.should == @photo1.id
|
128
|
+
|
129
|
+
@album.photos.find(:last, :order => "asc").id.should == @photo1.id
|
130
|
+
@album.photos.find(:last, :order => "desc").id.should == @photo2.id
|
131
|
+
|
132
|
+
@album.photos.find(:last, :order => "desc", :offset => 2).should == nil
|
133
|
+
@album.photos.find(:first, :order => "desc", :offset => 2).should == nil
|
134
|
+
|
124
135
|
@album.photos.find(:all, :order => "asc", :limit => 1, :offset => 1).map{|p| p.id}.should == [@photo1.id]
|
125
136
|
@album.photos.find(:all, :order => "desc", :limit => 1, :offset => 1).map{|p| p.id}.should == [@photo2.id]
|
126
137
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_orm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-06 00:00:00.000000000 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
17
|
-
requirement: &
|
17
|
+
requirement: &85879940 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 3.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *85879940
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activemodel
|
28
|
-
requirement: &
|
28
|
+
requirement: &85879580 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 3.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *85879580
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: redis
|
39
|
-
requirement: &
|
39
|
+
requirement: &85879180 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 2.2.0
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *85879180
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
|
-
requirement: &
|
50
|
+
requirement: &85878840 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: 2.5.0
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *85878840
|
59
59
|
description: ORM for Redis advanced key-value storage
|
60
60
|
email: germaninthetown@gmail.com
|
61
61
|
executables: []
|