redis_storage 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- 1.9.3-p125
1
+ 1.9.3-p194
data/Gemfile CHANGED
@@ -5,6 +5,6 @@ gemspec
5
5
 
6
6
  group :development, :test do
7
7
  gem 'guard-rspec'
8
- gem 'pry'
9
- gem 'pry-nav'
8
+ #gem 'pry'
9
+ #gem 'pry-nav'
10
10
  end
@@ -57,7 +57,7 @@ module RedisStorage
57
57
  if key == :id
58
58
  load "#{db_key}:#{value}"
59
59
  elsif indizies.include? key
60
- load($db.get("#{db_key}:#{key}:#{value.hash}"))
60
+ load_many $db.smembers("#{db_key}:#{key}:#{value.hash}")
61
61
  else
62
62
  nil
63
63
  end
@@ -66,13 +66,7 @@ module RedisStorage
66
66
  def self.all
67
67
  keys = $db.smembers(persisted_key)
68
68
 
69
- if keys.empty?
70
- []
71
- else
72
- $db.mget(*keys).inject([]) do |a,json|
73
- a << new(JSON.parse(json))
74
- end
75
- end
69
+ load_many keys
76
70
  end
77
71
 
78
72
  def self.count
@@ -110,7 +104,7 @@ module RedisStorage
110
104
  $db.set db_key, to_json
111
105
  $db.sadd self.class.persisted_key, db_key
112
106
  indizies.each do |key|
113
- $db.set "#{self.class.db_key}:#{key}:#{send(key).hash}", db_key
107
+ $db.sadd "#{self.class.db_key}:#{key}:#{send(key).hash}", db_key
114
108
  end
115
109
  end
116
110
  @id
@@ -128,7 +122,7 @@ module RedisStorage
128
122
  $db.del db_key
129
123
  $db.srem self.class.persisted_key, db_key
130
124
  indizies.each do |key|
131
- $db.del "#{self.class.db_key}:#{key}:#{send(key).hash}"
125
+ $db.srem "#{self.class.db_key}:#{key}:#{send(key).hash}", db_key
132
126
  end
133
127
  end
134
128
  true
@@ -165,11 +159,22 @@ module RedisStorage
165
159
  end
166
160
  end
167
161
  private
168
- def self.load(key)
162
+ def self.load key
169
163
  return nil if key.nil?
170
164
  r = $db.get(key)
171
165
  new(JSON.parse(r)) unless r.nil?
172
166
  end
167
+ def self.load_many keys
168
+ if keys.empty?
169
+ nil
170
+ elsif keys.count == 1
171
+ load keys.first
172
+ else
173
+ $db.mget(*keys).inject([]) do |a,json|
174
+ a << new(JSON.parse(json))
175
+ end
176
+ end
177
+ end
173
178
  def self.next_id_key
174
179
  "#{db_key}:next_id"
175
180
  end
@@ -1,3 +1,3 @@
1
1
  module RedisStorage
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
  class MockModel < RedisStorage::Model
3
- attribute :body, :title
4
- index :title
3
+ attribute :body, :title, :user_id
4
+ index :title, :user_id
5
5
  end
6
6
 
7
7
  describe RedisStorage::Model do
8
8
  it_should_behave_like "ActiveModel"
9
9
  let(:modelhash) do
10
- {'body'=>"Lorem Ipsum", 'title' => "some test"}
10
+ {'body'=>"Lorem Ipsum", 'title' => "some test", 'user_id' => 3}
11
11
  end
12
12
 
13
13
  context 'class' do
@@ -41,10 +41,11 @@ describe RedisStorage::Model do
41
41
  end
42
42
  context '#find' do
43
43
  let(:h) do
44
- [ {'body' =>"Lorem Ipsum", 'title' => "first test"},
45
- {'body' =>"Dolor Sit", 'title' => "second test"},
46
- {'body' =>"Amet consetetur", 'title' => "third test"},
47
- {'body' =>"sadipscing elitr", 'title' => "forth test"}]
44
+ [ {'body' =>"Lorem Ipsum", 'title' => "first test", 'user_id' => 1},
45
+ {'body' =>"Dolor Sit", 'title' => "second test", 'user_id' => 2},
46
+ {'body' =>"Amet consetetur", 'title' => "third test", 'user_id' => 3},
47
+ {'body' =>"sadipscing elitr", 'title' => "forth test", 'user_id' => 2},
48
+ {'body' =>"Vivamus fermentum", 'title' => "fifth test", 'user_id' => 3}]
48
49
  end
49
50
  before(:each) do
50
51
  h.each do |e|
@@ -64,7 +65,7 @@ describe RedisStorage::Model do
64
65
  MockModel.expects(:load)
65
66
  MockModel.find_by(:id,3)
66
67
  end
67
- 1.upto(4) do |i|
68
+ 1.upto(5) do |i|
68
69
  it "should find record #{i} by id, load it and create a new instance" do
69
70
  record = MockModel.find_by :id, i
70
71
  record.id.should == i
@@ -91,16 +92,26 @@ describe RedisStorage::Model do
91
92
  n = MockModel.find_by :title, t
92
93
  n.should be_nil
93
94
  end
95
+ context "nonunique" do
96
+ it "should give the object directly if only a single one availabe" do
97
+ m = MockModel.find_by :user_id, 1
98
+ m.body.should == h[0]['body']
99
+ end
100
+ it "should deliver a array of objects of multiple one in db" do
101
+ m = MockModel.find_by :user_id, 2
102
+ m.should have(2).things
103
+ end
104
+ end
94
105
  end
95
106
  context '#all' do
96
107
  it 'should return an empty array if there are no entries' do
97
108
  MockRedis.any_instance.stubs(:smembers => [])
98
109
  records = MockModel.all
99
- records.should eq([])
110
+ records.should be_nil
100
111
  end
101
112
  it 'should return all entries' do
102
113
  records = MockModel.all
103
- records.size.should eq(4)
114
+ records.should have(h.count).things
104
115
  end
105
116
  it 'should return an Array with all entries' do
106
117
  records = MockModel.all
@@ -123,7 +134,7 @@ describe RedisStorage::Model do
123
134
  end
124
135
  context '#last' do
125
136
  it 'should return the instance with the newest - highest id' do
126
- MockModel.last.id.should eq(4)
137
+ MockModel.last.id.should eq(h.count)
127
138
  end
128
139
  end
129
140
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-21 00:00:00.000000000 Z
12
+ date: 2012-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &108020580 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 2.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *108020580
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.2.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: json
27
- requirement: &108036480 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *108036480
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: activemodel
38
- requirement: &108032540 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 3.0.0
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *108032540
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec
49
- requirement: &108088580 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 2.8.0
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *108088580
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.8.0
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: mocha
60
- requirement: &108087020 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: 0.10.4
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *108087020
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.10.4
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: mock_redis
71
- requirement: &108086340 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: 0.3.0
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *108086340
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 0.3.0
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: generator_spec
82
- requirement: &108085660 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: 0.8.5
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *108085660
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 0.8.5
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: rails
93
- requirement: &108084680 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>='
@@ -98,7 +133,12 @@ dependencies:
98
133
  version: 3.2.0
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *108084680
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: 3.2.0
102
142
  description: Provides a data backend for a Redis in Rails, will also provide a Rails
103
143
  3 Generator
104
144
  email:
@@ -139,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
179
  version: '0'
140
180
  segments:
141
181
  - 0
142
- hash: 3658108810072488555
182
+ hash: 2046715117829460915
143
183
  required_rubygems_version: !ruby/object:Gem::Requirement
144
184
  none: false
145
185
  requirements:
@@ -148,10 +188,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
188
  version: '0'
149
189
  segments:
150
190
  - 0
151
- hash: 3658108810072488555
191
+ hash: 2046715117829460915
152
192
  requirements: []
153
193
  rubyforge_project: redis_storage
154
- rubygems_version: 1.8.11
194
+ rubygems_version: 1.8.23
155
195
  signing_key:
156
196
  specification_version: 3
157
197
  summary: A simple Redis ORM for Rails