toystore 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -7,4 +7,7 @@ group(:development) do
7
7
  gem 'timecop', '~> 0.3.5'
8
8
  gem 'tzinfo', '~> 0.3.23'
9
9
  gem 'log_buddy', '~> 0.5.0'
10
+
11
+ gem 'bson'
12
+ gem 'bson_ext'
10
13
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- toystore (0.5)
4
+ toystore (0.6)
5
5
  activemodel (~> 3.0.3)
6
6
  activesupport (~> 3.0.3)
7
7
  adapter (~> 0.5.1)
@@ -16,6 +16,8 @@ GEM
16
16
  i18n (~> 0.4)
17
17
  activesupport (3.0.3)
18
18
  adapter (0.5.1)
19
+ bson (1.2.0)
20
+ bson_ext (1.2.0)
19
21
  builder (2.1.2)
20
22
  diff-lcs (1.1.2)
21
23
  i18n (0.5.0)
@@ -40,6 +42,8 @@ DEPENDENCIES
40
42
  activemodel (~> 3.0.3)
41
43
  activesupport (~> 3.0.3)
42
44
  adapter (~> 0.5.1)
45
+ bson
46
+ bson_ext
43
47
  log_buddy (~> 0.5.0)
44
48
  rake (~> 0.8.7)
45
49
  rspec (~> 2.3)
@@ -0,0 +1,16 @@
1
+ require 'pp'
2
+ require 'rubygems'
3
+ require 'pathname'
4
+
5
+ root_path = Pathname(__FILE__).dirname.join('..').expand_path
6
+ lib_path = root_path.join('lib')
7
+ $:.unshift(lib_path)
8
+
9
+ require 'toystore'
10
+
11
+ class User
12
+ include Toy::Store
13
+ key :object_id
14
+ end
15
+
16
+ puts User.new.id # BSON::ObjectId ...
@@ -0,0 +1,20 @@
1
+ require 'pp'
2
+ require 'rubygems'
3
+ require 'toystore'
4
+ require 'adapter/riak'
5
+
6
+ class GameList
7
+ include Toy::Store
8
+ store :riak, Riak::Client.new['adapter_example']
9
+
10
+ attribute :source, Hash
11
+ end
12
+
13
+ list = GameList.create(:source => {'foo' => 'bar'})
14
+
15
+ pp list
16
+ pp GameList.get(list.id)
17
+
18
+ list.destroy
19
+
20
+ pp GameList.get(list.id)
@@ -11,6 +11,9 @@ module Toy
11
11
  @key_factory = case name_or_factory
12
12
  when :uuid
13
13
  UUIDKeyFactory.new
14
+ when :object_id
15
+ require 'toy/identity/object_id_key_factory'
16
+ ObjectIdKeyFactory.new
14
17
  else
15
18
  name_or_factory
16
19
  end
@@ -0,0 +1,11 @@
1
+ require 'bson'
2
+
3
+ module Toy
4
+ module Identity
5
+ class ObjectIdKeyFactory < AbstractKeyFactory
6
+ def next_key(object)
7
+ BSON::ObjectId.new
8
+ end
9
+ end
10
+ end
11
+ end
@@ -25,18 +25,8 @@ module Toy
25
25
  !@cache.nil?
26
26
  end
27
27
 
28
- def namespace(new_namespace=nil)
29
- if new_namespace.nil?
30
- @namespace ||= self.name
31
- else
32
- @namespace = new_namespace
33
- end
34
-
35
- @namespace
36
- end
37
-
38
28
  def store_key(id)
39
- [namespace, id].join(':')
29
+ id
40
30
  end
41
31
 
42
32
  def create(attrs={})
@@ -1,3 +1,3 @@
1
1
  module Toy
2
- VERSION = "0.5"
2
+ VERSION = "0.6"
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'helper'
2
+ require 'toy/identity/object_id_key_factory'
3
+
4
+ describe Toy::Identity::ObjectIdKeyFactory do
5
+ it "should use object id for next key" do
6
+ key = Toy::Identity::ObjectIdKeyFactory.new.next_key(nil)
7
+ key.should be_instance_of(BSON::ObjectId)
8
+ end
9
+ end
@@ -8,6 +8,10 @@ describe Toy::Identity do
8
8
  User.key(:uuid).should be_instance_of(Toy::Identity::UUIDKeyFactory)
9
9
  end
10
10
 
11
+ it "should use ObjectIdKeyFactory if :object_id" do
12
+ User.key(:object_id).should be_instance_of(Toy::Identity::ObjectIdKeyFactory)
13
+ end
14
+
11
15
  it "should set key factory passed in factory" do
12
16
  factory = Toy::Identity::UUIDKeyFactory
13
17
  User.key(factory).should == factory
@@ -73,23 +73,9 @@ describe Toy::Persistence do
73
73
  end
74
74
 
75
75
  describe ".store_key" do
76
- it "returns namespace and id" do
76
+ it "returns id" do
77
77
  doc = User.new
78
-
79
- User.store_key(doc.id).should == "User:#{doc.id}"
80
- User.namespace('Crazy')
81
- User.store_key(doc.id).should == "Crazy:#{doc.id}"
82
- end
83
- end
84
-
85
- describe ".namespace" do
86
- it "defaults to class name" do
87
- User.namespace.should == 'User'
88
- end
89
-
90
- it "sets if argument and reads if not" do
91
- User.namespace('CrazyUser')
92
- User.namespace.should == 'CrazyUser'
78
+ User.store_key(doc.id).should == doc.id
93
79
  end
94
80
  end
95
81
 
@@ -167,9 +153,9 @@ describe Toy::Persistence do
167
153
  end
168
154
 
169
155
  describe "#store_key" do
170
- it "returns pluralized human name and id" do
156
+ it "returns id" do
171
157
  doc = User.new
172
- doc.store_key.should == "User:#{doc.id}"
158
+ doc.store_key.should == doc.id
173
159
  end
174
160
  end
175
161
 
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toystore
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
9
- version: "0.5"
8
+ - 6
9
+ version: "0.6"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Geoffrey Dagley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-26 00:00:00 -05:00
18
+ date: 2011-02-03 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -102,10 +102,12 @@ files:
102
102
  - LOGGING.rdoc
103
103
  - README.rdoc
104
104
  - Rakefile
105
+ - examples/changing_key_factory.rb
105
106
  - examples/memcached.rb
106
107
  - examples/memory.rb
107
108
  - examples/models.rb
108
109
  - examples/redis.rb
110
+ - examples/riak.rb
109
111
  - lib/toy.rb
110
112
  - lib/toy/attribute.rb
111
113
  - lib/toy/attributes.rb
@@ -132,6 +134,7 @@ files:
132
134
  - lib/toy/extensions/time.rb
133
135
  - lib/toy/identity.rb
134
136
  - lib/toy/identity/abstract_key_factory.rb
137
+ - lib/toy/identity/object_id_key_factory.rb
135
138
  - lib/toy/identity/uuid_key_factory.rb
136
139
  - lib/toy/identity_map.rb
137
140
  - lib/toy/index.rb
@@ -182,6 +185,7 @@ files:
182
185
  - spec/toy/extensions/string_spec.rb
183
186
  - spec/toy/extensions/time_spec.rb
184
187
  - spec/toy/identity/abstract_key_factory_spec.rb
188
+ - spec/toy/identity/object_id_key_factory_spec.rb
185
189
  - spec/toy/identity/uuid_key_factory_spec.rb
186
190
  - spec/toy/identity_map_spec.rb
187
191
  - spec/toy/identity_spec.rb
@@ -267,6 +271,7 @@ test_files:
267
271
  - spec/toy/extensions/string_spec.rb
268
272
  - spec/toy/extensions/time_spec.rb
269
273
  - spec/toy/identity/abstract_key_factory_spec.rb
274
+ - spec/toy/identity/object_id_key_factory_spec.rb
270
275
  - spec/toy/identity/uuid_key_factory_spec.rb
271
276
  - spec/toy/identity_map_spec.rb
272
277
  - spec/toy/identity_spec.rb