toystore 0.6 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- toystore (0.6)
4
+ toystore (0.6.1)
5
5
  activemodel (~> 3.0.3)
6
6
  activesupport (~> 3.0.3)
7
7
  adapter (~> 0.5.1)
data/examples/mongo.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'pp'
2
+ require 'rubygems'
3
+ require 'toystore'
4
+ require 'adapter/mongo'
5
+
6
+ class User
7
+ include Toy::Store
8
+ store :mongo, Mongo::Connection.new.db('adapter')['testing']
9
+
10
+ attribute :name, String
11
+ end
12
+
13
+ user = User.create(:name => 'John')
14
+
15
+ pp user
16
+ pp User.get(user.id)
17
+
18
+ user.destroy
19
+
20
+ pp User.get(user.id)
@@ -0,0 +1,32 @@
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 NamespacedUUIDKeyFactory < Toy::Identity::AbstractKeyFactory
12
+ def next_key(object)
13
+ [object.class.name, SimpleUUID::UUID.new.to_guid].join(':')
14
+ end
15
+ end
16
+
17
+ class User
18
+ include Toy::Store
19
+ key NamespacedUUIDKeyFactory.new
20
+ end
21
+
22
+ puts User.new.id # User:some_uuid
23
+
24
+ # or use namespaces for all classes
25
+
26
+ Toy.key_factory = NamespacedUUIDKeyFactory.new
27
+
28
+ class Game
29
+ include Toy::Store
30
+ end
31
+
32
+ puts Game.new.id # Game:some_uuid
@@ -3,7 +3,7 @@ module Toy
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- def store(name=nil, client=nil, options=nil)
6
+ def store(name=nil, client=nil, options={})
7
7
  assert_client(name, client)
8
8
  @store = Adapter[name].new(client, options) if !name.nil? && !client.nil?
9
9
  assert_store(name, client, 'store')
@@ -120,7 +120,7 @@ module Toy
120
120
  store.write(key, attrs)
121
121
  log_operation('SET', store, key, attrs)
122
122
  persist
123
- each_embedded_object(&:persist)
123
+ each_embedded_object { |doc| doc.send(:persist) }
124
124
  true
125
125
  end
126
126
  end
data/lib/toy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Toy
2
- VERSION = "0.6"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -13,6 +13,11 @@ describe Toy::Persistence do
13
13
  User.store.should == Adapter[:memory].new({})
14
14
  end
15
15
 
16
+ it "defaults options to empty hash" do
17
+ Adapter[:memory].should_receive(:new).with({}, {})
18
+ User.store(:memory, {})
19
+ end
20
+
16
21
  it "works with options" do
17
22
  Adapter[:memory].should_receive(:new).with({}, :something => true)
18
23
  User.store(:memory, {}, :something => true)
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: 7
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 6
9
- version: "0.6"
8
+ - 1
9
+ version: 0.6.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Geoffrey Dagley
@@ -26,7 +26,6 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 9
30
29
  segments:
31
30
  - 0
32
31
  - 5
@@ -42,7 +41,6 @@ dependencies:
42
41
  requirements:
43
42
  - - ~>
44
43
  - !ruby/object:Gem::Version
45
- hash: 1
46
44
  segments:
47
45
  - 3
48
46
  - 0
@@ -58,7 +56,6 @@ dependencies:
58
56
  requirements:
59
57
  - - ~>
60
58
  - !ruby/object:Gem::Version
61
- hash: 1
62
59
  segments:
63
60
  - 3
64
61
  - 0
@@ -74,7 +71,6 @@ dependencies:
74
71
  requirements:
75
72
  - - ~>
76
73
  - !ruby/object:Gem::Version
77
- hash: 25
78
74
  segments:
79
75
  - 0
80
76
  - 1
@@ -106,6 +102,8 @@ files:
106
102
  - examples/memcached.rb
107
103
  - examples/memory.rb
108
104
  - examples/models.rb
105
+ - examples/mongo.rb
106
+ - examples/namespacing_keys.rb
109
107
  - examples/redis.rb
110
108
  - examples/riak.rb
111
109
  - lib/toy.rb
@@ -223,7 +221,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
223
221
  requirements:
224
222
  - - ">="
225
223
  - !ruby/object:Gem::Version
226
- hash: 3
227
224
  segments:
228
225
  - 0
229
226
  version: "0"
@@ -232,7 +229,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
229
  requirements:
233
230
  - - ">="
234
231
  - !ruby/object:Gem::Version
235
- hash: 3
236
232
  segments:
237
233
  - 0
238
234
  version: "0"