toystore 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +5 -1
- data/examples/changing_key_factory.rb +16 -0
- data/examples/riak.rb +20 -0
- data/lib/toy/identity.rb +3 -0
- data/lib/toy/identity/object_id_key_factory.rb +11 -0
- data/lib/toy/persistence.rb +1 -11
- data/lib/toy/version.rb +1 -1
- data/spec/toy/identity/object_id_key_factory_spec.rb +9 -0
- data/spec/toy/identity_spec.rb +4 -0
- data/spec/toy/persistence_spec.rb +4 -18
- metadata +9 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
toystore (0.
|
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 ...
|
data/examples/riak.rb
ADDED
@@ -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)
|
data/lib/toy/identity.rb
CHANGED
data/lib/toy/persistence.rb
CHANGED
@@ -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
|
-
|
29
|
+
id
|
40
30
|
end
|
41
31
|
|
42
32
|
def create(attrs={})
|
data/lib/toy/version.rb
CHANGED
@@ -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
|
data/spec/toy/identity_spec.rb
CHANGED
@@ -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
|
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
|
156
|
+
it "returns id" do
|
171
157
|
doc = User.new
|
172
|
-
doc.store_key.should ==
|
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:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
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-
|
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
|