dm-redis-adapter 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -38,7 +38,7 @@ Setup your adapter, define your models and properties:
38
38
  <code>
39
39
  require 'rubygems'
40
40
  require 'dm-core'
41
- require 'dm_redis'
41
+ require 'dm-redis-adapter'
42
42
 
43
43
  DataMapper.setup(:default, {:adapter => "redis"})
44
44
 
data/Rakefile CHANGED
@@ -26,8 +26,8 @@ begin
26
26
  gemspec.homepage = HOMEPAGE
27
27
  gemspec.description = SUMMARY
28
28
  gemspec.authors = AUTHORS
29
- gemspec.add_dependency "dm-core", ">= 1.1.0"
30
- gemspec.add_dependency "dm-types", ">= 1.1.0"
29
+ gemspec.add_dependency "dm-core", ">= 1.2.0"
30
+ gemspec.add_dependency "dm-types", ">= 1.2.0"
31
31
  gemspec.add_dependency "hiredis", "~> 0.3.0"
32
32
  gemspec.add_dependency "redis", "~> 2.2"
33
33
  gemspec.files = %w(MIT-LICENSE README.textile Rakefile) + Dir.glob("{lib,spec}/**/*")
@@ -89,8 +89,7 @@ module DataMapper
89
89
  #
90
90
  # @api semipublic
91
91
  def delete(collection)
92
- collection.count.times do |x|
93
- record = collection[x]
92
+ collection.each do |record|
94
93
  @redis.del("#{collection.query.model.to_s.downcase}:#{record[redis_key_for(collection.query.model)]}")
95
94
  @redis.srem(key_set_for(collection.query.model), record[redis_key_for(collection.query.model)])
96
95
  record.model.properties.select {|p| p.index}.each do |p|
@@ -6,6 +6,9 @@ module DataMapper
6
6
  module Adapters
7
7
 
8
8
  class RedisAdapter < Adapter
9
+ def connection_uri
10
+ { :adapter => "redis", :db => 15 }
11
+ end
9
12
  end
10
13
 
11
14
  use RedisAdapter
@@ -38,6 +38,8 @@ describe DataMapper::Adapters::RedisAdapter do
38
38
  belongs_to :tag
39
39
  end
40
40
 
41
+ DataMapper.finalize
42
+
41
43
  b = Book.create(:name => "Harry Potter")
42
44
  t = Tag.create(:name => "fiction")
43
45
 
@@ -21,6 +21,7 @@ describe DataMapper::Adapters::RedisAdapter do
21
21
  property :iq, Integer
22
22
  property :shade, String, :index => true
23
23
  end
24
+ DataMapper.finalize
24
25
  end
25
26
 
26
27
  it "should save the id of the resource in a set" do
@@ -18,6 +18,7 @@ describe DataMapper::Adapters::RedisAdapter do
18
18
  property :id, Serial
19
19
  property :flavor, String, :index => true
20
20
  end
21
+ DataMapper.finalize
21
22
 
22
23
  Crumblecake.create(:flavor => "snozzbler")
23
24
  Crumblecake.new(:flavor => "snozzbler").valid?.should be_false
@@ -32,6 +33,7 @@ describe DataMapper::Adapters::RedisAdapter do
32
33
  property :name, String
33
34
  property :env, DataMapper::Property::Json, :default => {}
34
35
  end
36
+ DataMapper.finalize
35
37
  end
36
38
 
37
39
  it "should be able to store json blocks" do
@@ -56,6 +58,7 @@ describe DataMapper::Adapters::RedisAdapter do
56
58
  property :id, Serial
57
59
  property :name, String
58
60
  end
61
+ DataMapper.finalize
59
62
 
60
63
  u = User.create :name => "bpo"
61
64
  u.reload.name.should == "bpo"
@@ -71,6 +74,7 @@ describe DataMapper::Adapters::RedisAdapter do
71
74
  property :id, Serial
72
75
  property :posted_at, Date
73
76
  end
77
+ DataMapper.finalize
74
78
 
75
79
  Post.create :posted_at => Date.today
76
80
  Post.first.posted_at.should be_a(Date)
@@ -83,6 +87,7 @@ describe DataMapper::Adapters::RedisAdapter do
83
87
  property :id, Serial
84
88
  property :nickname, String
85
89
  end
90
+ DataMapper.finalize
86
91
 
87
92
  joey = GangMember.create(:nickname => "Joey 'two-times'")
88
93
  bobby = GangMember.create(:nickname => "Bobby 'three-fingers'")
@@ -91,31 +96,29 @@ describe DataMapper::Adapters::RedisAdapter do
91
96
  GangMember.last.should == bobby
92
97
  end
93
98
 
94
- it "should pull up the first pirate that matches the nickname" do
95
- class Blackguard
96
- include DataMapper::Resource
99
+ describe "Finding a record by an indexed value" do
100
+ before(:each) do
101
+ class Blackguard
102
+ include DataMapper::Resource
97
103
 
98
- property :id, Serial
99
- property :nickname, String, :index => true
104
+ property :id, Serial
105
+ property :nickname, String, :index => true
106
+ end
107
+ DataMapper.finalize
100
108
  end
101
109
 
102
- petey = Blackguard.create(:nickname => "Petey 'one-eye' McGraw")
103
- james = Blackguard.create(:nickname => "James 'cannon-fingers' Doolittle")
104
- Blackguard.first(:nickname => "James 'cannon-fingers' Doolittle").should == james
105
- end
106
-
107
- it "should not mark the first pirate as destroyed" do
108
- class Blackguard
109
- include DataMapper::Resource
110
-
111
- property :id, Serial
112
- property :nickname, String, :index => true
110
+ it "should pull up the first pirate that matches the nickname" do
111
+ petey = Blackguard.create(:nickname => "Petey 'one-eye' McGraw")
112
+ james = Blackguard.create(:nickname => "James 'cannon-fingers' Doolittle")
113
+ Blackguard.first(:nickname => "James 'cannon-fingers' Doolittle").should == james
113
114
  end
114
115
 
115
- petey = Blackguard.create(:nickname => "Petey 'one-eye' McGraw")
116
- james = Blackguard.create(:nickname => "James 'cannon-fingers' Doolittle")
117
- Blackguard.get(petey.id).should_not be_destroyed
118
- Blackguard.first(:nickname => "James 'cannon-fingers' Doolittle").should_not be_destroyed
116
+ it "should not mark the first pirate as destroyed" do
117
+ petey = Blackguard.create(:nickname => "Petey 'one-eye' McGraw")
118
+ james = Blackguard.create(:nickname => "James 'cannon-fingers' Doolittle")
119
+ Blackguard.get(petey.id).should_not be_destroyed
120
+ Blackguard.first(:nickname => "James 'cannon-fingers' Doolittle").should_not be_destroyed
121
+ end
119
122
  end
120
123
 
121
124
  after(:each) do
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
7
+ - 5
8
8
  - 0
9
- version: 0.4.0
9
+ version: 0.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dan Herrera
@@ -14,12 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-17 00:00:00 -07:00
17
+ date: 2011-11-12 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: dm-core
22
- prerelease: false
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
24
23
  none: false
25
24
  requirements:
@@ -27,14 +26,14 @@ dependencies:
27
26
  - !ruby/object:Gem::Version
28
27
  segments:
29
28
  - 1
30
- - 1
29
+ - 2
31
30
  - 0
32
- version: 1.1.0
31
+ version: 1.2.0
33
32
  type: :runtime
33
+ prerelease: false
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: dm-types
37
- prerelease: false
38
37
  requirement: &id002 !ruby/object:Gem::Requirement
39
38
  none: false
40
39
  requirements:
@@ -42,14 +41,14 @@ dependencies:
42
41
  - !ruby/object:Gem::Version
43
42
  segments:
44
43
  - 1
45
- - 1
44
+ - 2
46
45
  - 0
47
- version: 1.1.0
46
+ version: 1.2.0
48
47
  type: :runtime
48
+ prerelease: false
49
49
  version_requirements: *id002
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: hiredis
52
- prerelease: false
53
52
  requirement: &id003 !ruby/object:Gem::Requirement
54
53
  none: false
55
54
  requirements:
@@ -61,10 +60,10 @@ dependencies:
61
60
  - 0
62
61
  version: 0.3.0
63
62
  type: :runtime
63
+ prerelease: false
64
64
  version_requirements: *id003
65
65
  - !ruby/object:Gem::Dependency
66
66
  name: redis
67
- prerelease: false
68
67
  requirement: &id004 !ruby/object:Gem::Requirement
69
68
  none: false
70
69
  requirements:
@@ -75,6 +74,7 @@ dependencies:
75
74
  - 2
76
75
  version: "2.2"
77
76
  type: :runtime
77
+ prerelease: false
78
78
  version_requirements: *id004
79
79
  description: DataMapper adapter for the Redis key-value database
80
80
  email: whoahbot@gmail.com
@@ -109,6 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
+ hash: 2716290058136044164
112
113
  segments:
113
114
  - 0
114
115
  version: "0"