toystore-mongo 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,7 +10,7 @@ Mongo integration for Toystore.
10
10
 
11
11
  class User
12
12
  include Toy::Mongo
13
- store Mongo::Connection.new.db('myapp')['users']
13
+ adapter :mongo, Mongo::Connection.new.db('myapp')['users']
14
14
 
15
15
  attribute :name, String
16
16
  end
@@ -1,9 +1,13 @@
1
- class BSON::ObjectId
2
- def self.to_store(value, *)
1
+ module ObjectIdConversions
2
+ def to_store(value, *)
3
3
  Plucky.to_object_id(value)
4
4
  end
5
5
 
6
- def self.from_store(value, *args)
6
+ def from_store(value, *)
7
7
  Plucky.to_object_id(value)
8
8
  end
9
9
  end
10
+
11
+ class BSON::ObjectId
12
+ extend ObjectIdConversions
13
+ end
@@ -51,7 +51,7 @@ module Toy
51
51
 
52
52
  def query
53
53
  # TODO: add object id keys to convert
54
- Plucky::Query.new(store.client, :transformer => transformer).object_ids(object_id_attributes)
54
+ Plucky::Query.new(adapter.client, :transformer => transformer).object_ids(object_id_attributes)
55
55
  end
56
56
 
57
57
  PluckyMethods.each do |name|
@@ -85,7 +85,7 @@ module Toy
85
85
  run_callbacks(:update) do
86
86
  criteria = {'_id' => id}
87
87
  update = {'$set' => persistable_changes}
88
- store.client.update(criteria, update, {:safe => store.options[:safe]})
88
+ adapter.client.update(criteria, update, {:safe => adapter.options[:safe]})
89
89
  true
90
90
  end
91
91
  end
@@ -98,11 +98,11 @@ module Toy
98
98
  options = {}
99
99
  criteria = {'_id' => id}
100
100
  criteria.update(opts[:criteria]) if opts[:criteria]
101
- options[:safe] = opts.key?(:safe) ? opts[:safe] : store.options[:safe]
101
+ options[:safe] = opts.key?(:safe) ? opts[:safe] : adapter.options[:safe]
102
102
 
103
103
  run_callbacks(:save) do
104
104
  run_callbacks(:update) do
105
- store.client.update(criteria, update, options)
105
+ adapter.client.update(criteria, update, options)
106
106
  end
107
107
  end
108
108
  end
@@ -1,5 +1,5 @@
1
1
  module Toy
2
2
  module Mongo
3
- VERSION = '0.8.2'
3
+ VERSION = '0.9.0'
4
4
  end
5
5
  end
@@ -33,8 +33,9 @@ module Support
33
33
  def self.name; '#{name}' end
34
34
  def self.to_s; '#{name}' end
35
35
  """ if name
36
- model.send(:include, Toy::Mongo)
37
- model.store(:mongo, STORE)
36
+
37
+ model.send :include, Toy::Mongo
38
+ model.adapter :mongo, STORE
38
39
  end
39
40
  end
40
41
  end
@@ -29,7 +29,7 @@ describe Toy::Identity::ObjectIdKeyFactory do
29
29
  it "correctly stores id in database" do
30
30
  user = User.create(:name => 'John')
31
31
  user.id.should be_instance_of(BSON::ObjectId)
32
- key = user.store.client.find_one(user.id)['_id']
32
+ key = user.adapter.client.find_one(user.id)['_id']
33
33
  key.should be_instance_of(BSON::ObjectId)
34
34
  user.id.should == key
35
35
  end
@@ -5,7 +5,6 @@ describe Toy::Mongo::Querying do
5
5
 
6
6
  before(:each) do
7
7
  User.send(:include, CallbacksHelper)
8
- User.identity_map_off
9
8
  User.attribute(:name, String)
10
9
  User.attribute(:bio, String)
11
10
  end
@@ -36,16 +35,16 @@ describe Toy::Mongo::Querying do
36
35
  @user.name.should == 'Frank'
37
36
  end
38
37
 
39
- it "defaults to store's :safe option" do
40
- @user.store.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => nil)
38
+ it "defaults to adapter's :safe option" do
39
+ @user.adapter.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => nil)
41
40
  @user.atomic_update('$set' => {'name' => 'Frank'})
42
41
 
43
- User.store(:mongo, STORE, :safe => false)
44
- @user.store.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => false)
42
+ User.adapter(:mongo, STORE, :safe => false)
43
+ @user.adapter.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => false)
45
44
  @user.atomic_update('$set' => {'name' => 'Frank'})
46
45
 
47
- User.store(:mongo, STORE, :safe => true)
48
- @user.store.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => true)
46
+ User.adapter(:mongo, STORE, :safe => true)
47
+ @user.adapter.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => true)
49
48
  @user.atomic_update('$set' => {'name' => 'Frank'})
50
49
  end
51
50
 
@@ -56,13 +55,13 @@ describe Toy::Mongo::Querying do
56
55
  end
57
56
 
58
57
  context "with :safe option" do
59
- it "overrides store's :safe option" do
60
- User.store(:mongo, STORE, :safe => false)
61
- @user.store.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => true)
58
+ it "overrides adapter's :safe option" do
59
+ User.adapter(:mongo, STORE, :safe => false)
60
+ @user.adapter.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => true)
62
61
  @user.atomic_update({'$set' => {'name' => 'Frank'}}, :safe => true)
63
62
 
64
- User.store(:mongo, STORE, :safe => true)
65
- @user.store.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => false)
63
+ User.adapter(:mongo, STORE, :safe => true)
64
+ @user.adapter.client.should_receive(:update).with(kind_of(Hash), kind_of(Hash), :safe => false)
66
65
  @user.atomic_update({'$set' => {'name' => 'Frank'}}, :safe => false)
67
66
  end
68
67
  end
@@ -137,15 +136,15 @@ describe Toy::Mongo::Querying do
137
136
  it "only persists changes" do
138
137
  query = {'_id' => @user.id}
139
138
  update = {'$set' => {'name' => 'Frank'}}
140
- @user.store.client.should_receive(:update).with(query, update, {:safe => nil})
139
+ @user.adapter.client.should_receive(:update).with(query, update, {:safe => nil})
141
140
  @user.atomic_update_attributes(:name => 'Frank')
142
141
  end
143
142
 
144
- it "persists changes with safe option from store" do
145
- User.store(:mongo, STORE, :safe => true)
143
+ it "persists changes with safe option from adapter" do
144
+ User.adapter(:mongo, STORE, :safe => true)
146
145
  query = {'_id' => @user.id}
147
146
  update = {'$set' => {'name' => 'Frank'}}
148
- @user.store.client.should_receive(:update).with(query, update, {:safe => true})
147
+ @user.adapter.client.should_receive(:update).with(query, update, {:safe => true})
149
148
  @user.atomic_update_attributes(:name => 'Frank')
150
149
  end
151
150
 
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Mongo integration for Toystore}
14
14
 
15
15
  s.add_dependency('plucky', '~> 0.4.1')
16
- s.add_dependency('toystore', '~> 0.8.0')
16
+ s.add_dependency('toystore', '~> 0.9.0')
17
17
  s.add_dependency('adapter-mongo', '~> 0.5.3')
18
18
 
19
19
  s.files = `git ls-files`.split("\n") - ['specs.watchr']
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 8
9
- - 2
10
- version: 0.8.2
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Nunemaker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-09 00:00:00 Z
18
+ date: 2012-03-14 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: plucky
@@ -41,12 +41,12 @@ dependencies:
41
41
  requirements:
42
42
  - - ~>
43
43
  - !ruby/object:Gem::Version
44
- hash: 63
44
+ hash: 59
45
45
  segments:
46
46
  - 0
47
- - 8
47
+ - 9
48
48
  - 0
49
- version: 0.8.0
49
+ version: 0.9.0
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency