toystore 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,8 +4,6 @@ gemfile:
4
4
  - gemfiles/rails_3_0.gemfile
5
5
  language: ruby
6
6
  rvm:
7
- - 1.8.7
8
- - ree
9
7
  - 1.9.3
10
8
  notifications:
11
9
  email: false
@@ -1,5 +1,18 @@
1
1
  I will do my best to keep this up to date with significant changes here, starting in 0.8.3.
2
2
 
3
+ * 0.12.0
4
+
5
+ * Ruby 1.9 only. Officially not supporting Ruby 1.8.x.
6
+ * Added :native_uuid key factory for using when your data store supports them.
7
+ * Aliased .find and .read to .get.
8
+ * Aliased .find_multiple and .read_multiple to .get_multiple.
9
+
10
+ * 0.10.x => 0.11.0
11
+
12
+ * Added get_multiple which returns Hash of id pointed at instance.
13
+ * Aliased get_multi to get_multiple which means it now returns Hash instead of Array.
14
+ * Updated to latest version of adapter.
15
+
3
16
  * 0.10.4
4
17
  * Support for ActiveSupport/ActiveModel 3.2.*
5
18
 
data/README.md CHANGED
@@ -229,7 +229,7 @@ As of 0.8.3, I started keeping a [changelog](https://github.com/jnunemaker/toyst
229
229
  ## Compatibility
230
230
 
231
231
  * Rails 3.0.*, 3.1.*, 3.2.*, Sinatra, etc. No Rails 2 (because it uses Active Model).
232
- * Ruby 1.8.7, REE, and 1.9.3
232
+ * Ruby 1.9.3 only
233
233
 
234
234
  ## Mailing List
235
235
 
data/lib/toy.rb CHANGED
@@ -90,8 +90,9 @@ module Toy
90
90
  autoload 'Identity', 'toy/identity'
91
91
 
92
92
  module Identity
93
- autoload 'AbstractKeyFactory', 'toy/identity/abstract_key_factory'
94
- autoload 'UUIDKeyFactory', 'toy/identity/uuid_key_factory'
93
+ autoload 'AbstractKeyFactory', 'toy/identity/abstract_key_factory'
94
+ autoload 'UUIDKeyFactory', 'toy/identity/uuid_key_factory'
95
+ autoload 'NativeUUIDKeyFactory', 'toy/identity/native_uuid_key_factory'
95
96
  end
96
97
  end
97
98
 
@@ -0,0 +1,17 @@
1
+ module Toy
2
+ module Extensions
3
+ module UUID
4
+ def to_store(value, *)
5
+ SimpleUUID::UUID.new(value)
6
+ end
7
+
8
+ def from_store(value, *)
9
+ SimpleUUID::UUID.new(value)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ class SimpleUUID::UUID
16
+ extend Toy::Extensions::UUID
17
+ end
@@ -10,6 +10,8 @@ module Toy
10
10
  def key(name_or_factory = :uuid)
11
11
  @key_factory = if name_or_factory == :uuid
12
12
  UUIDKeyFactory.new
13
+ elsif name_or_factory == :native_uuid
14
+ NativeUUIDKeyFactory.new
13
15
  else
14
16
  if name_or_factory.respond_to?(:next_key) && name_or_factory.respond_to?(:key_type)
15
17
  name_or_factory
@@ -0,0 +1,13 @@
1
+ module Toy
2
+ module Identity
3
+ class NativeUUIDKeyFactory < AbstractKeyFactory
4
+ def key_type
5
+ SimpleUUID::UUID
6
+ end
7
+
8
+ def next_key(object)
9
+ SimpleUUID::UUID.new
10
+ end
11
+ end
12
+ end
13
+ end
@@ -9,10 +9,16 @@ module Toy
9
9
  end
10
10
  end
11
11
 
12
+ alias_method :read, :get
13
+ alias_method :find, :get
14
+
12
15
  def get!(id)
13
16
  get(id) || raise(Toy::NotFound.new(id))
14
17
  end
15
18
 
19
+ alias_method :read!, :get!
20
+ alias_method :find!, :get!
21
+
16
22
  def get_multiple(*ids)
17
23
  result = adapter.read_multiple(*ids.flatten)
18
24
  result.each do |id, attrs|
@@ -22,6 +28,8 @@ module Toy
22
28
  end
23
29
 
24
30
  alias_method :get_multi, :get_multiple
31
+ alias_method :read_multiple, :get_multiple
32
+ alias_method :find_multiple, :get_multiple
25
33
 
26
34
  def get_or_new(id)
27
35
  get(id) || new(:id => id)
@@ -1,3 +1,3 @@
1
1
  module Toy
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ describe "SimpleUUID::UUID.to_store" do
4
+ it "should convert value to uuid" do
5
+ uuid = SimpleUUID::UUID.new
6
+ [uuid, uuid.to_guid, uuid.to_s, uuid.to_i].each do |value|
7
+ SimpleUUID::UUID.from_store(value).should eq(uuid)
8
+ end
9
+ end
10
+ end
11
+
12
+ describe "SimpleUUID::UUID.from_store" do
13
+ it "should convert value to uuid" do
14
+ uuid = SimpleUUID::UUID.new
15
+ [uuid, uuid.to_guid, uuid.to_s, uuid.to_i].each do |value|
16
+ SimpleUUID::UUID.from_store(value).should eq(uuid)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,60 @@
1
+ require 'helper'
2
+
3
+ describe Toy::Identity::NativeUUIDKeyFactory do
4
+ uses_constants('User')
5
+
6
+ it "should use SimpleUUID::UUID as key_type" do
7
+ subject.key_type.should be(SimpleUUID::UUID)
8
+ end
9
+
10
+ it "should use uuid for next_key" do
11
+ result = subject.next_key(nil)
12
+ result.should be_instance_of(SimpleUUID::UUID)
13
+ end
14
+
15
+ describe "#eql?" do
16
+ it "returns true for same class and key type" do
17
+ subject.eql?(described_class.new).should be_true
18
+ end
19
+
20
+ it "returns false for same class and different key type" do
21
+ other = described_class.new
22
+ other.stub(:key_type).and_return(Integer)
23
+ subject.eql?(other).should be_false
24
+ end
25
+
26
+ it "returns false for different classes" do
27
+ subject.eql?(Object.new).should be_false
28
+ end
29
+ end
30
+
31
+ describe "#==" do
32
+ it "returns true for same class and key type" do
33
+ subject.==(described_class.new).should be_true
34
+ end
35
+
36
+ it "returns false for same class and different key type" do
37
+ other = described_class.new
38
+ other.stub(:key_type).and_return(Integer)
39
+ subject.==(other).should be_false
40
+ end
41
+
42
+ it "returns false for different classes" do
43
+ subject.==(Object.new).should be_false
44
+ end
45
+ end
46
+
47
+ describe "Declaring key to be uuid" do
48
+ before(:each) do
49
+ User.key(:native_uuid)
50
+ end
51
+
52
+ it "returns SimpleUUID::UUID as .key_type" do
53
+ User.key_type.should be(SimpleUUID::UUID)
54
+ end
55
+
56
+ it "sets id attribute to SimpleUUID::UUID type" do
57
+ User.attributes['id'].type.should be(SimpleUUID::UUID)
58
+ end
59
+ end
60
+ end
@@ -341,7 +341,6 @@ describe Toy::List do
341
341
  @user = User.create
342
342
  @game1 = @user.games.create
343
343
  @game2 = @user.games.create
344
- User.get(@user.id).games.should == [@game1, @game2]
345
344
  end
346
345
 
347
346
  it "should take multiple ids" do
@@ -396,7 +395,6 @@ describe Toy::List do
396
395
  @user = User.create
397
396
  @game1 = @user.games.create
398
397
  @game2 = @user.games.create
399
- User.get(@user.id).games.should == [@game1, @game2]
400
398
  end
401
399
 
402
400
  it "should destroy all" do
@@ -7,35 +7,35 @@ describe Toy::Querying do
7
7
  User.attribute :name, String
8
8
  end
9
9
 
10
- describe ".get" do
10
+ shared_examples_for "adapter read and load instance" do |method_name|
11
11
  it "returns document if found" do
12
12
  john = User.create(:name => 'John')
13
- User.get(john.id).name.should == 'John'
13
+ User.send(method_name, john.id).name.should == 'John'
14
14
  end
15
15
 
16
16
  it "returns nil if not found" do
17
- User.get('1').should be_nil
17
+ User.send(method_name, '1').should be_nil
18
18
  end
19
19
  end
20
20
 
21
- describe ".get!" do
21
+ shared_examples_for "adapter read and load instance with bang" do |method_name|
22
22
  it "returns document if found" do
23
23
  john = User.create(:name => 'John')
24
- User.get!(john.id).name.should == 'John'
24
+ User.send(method_name, john.id).name.should == 'John'
25
25
  end
26
26
 
27
27
  it "raises not found exception if not found" do
28
28
  lambda {
29
- User.get!('1')
29
+ User.send(method_name, '1')
30
30
  }.should raise_error(Toy::NotFound, 'Could not find document with id: "1"')
31
31
  end
32
32
  end
33
33
 
34
- describe ".get_multiple" do
34
+ shared_examples_for "adapter read_multiple and load instances" do |method_name|
35
35
  it "returns Hash of ids pointed at result" do
36
36
  john = User.create(:name => 'John')
37
37
  steve = User.create(:name => 'Steve')
38
- User.get_multiple(john.id, steve.id, 'foo').should == {
38
+ User.send(method_name, john.id, steve.id, 'foo').should == {
39
39
  john.id => john,
40
40
  steve.id => steve,
41
41
  'foo' => nil,
@@ -43,16 +43,44 @@ describe Toy::Querying do
43
43
  end
44
44
  end
45
45
 
46
+ describe ".get" do
47
+ include_examples "adapter read and load instance", :get
48
+ end
49
+
50
+ describe ".read" do
51
+ include_examples "adapter read and load instance", :read
52
+ end
53
+
54
+ describe ".find" do
55
+ include_examples "adapter read and load instance", :find
56
+ end
57
+
58
+ describe ".get!" do
59
+ include_examples "adapter read and load instance with bang", :get!
60
+ end
61
+
62
+ describe ".read!" do
63
+ include_examples "adapter read and load instance with bang", :read!
64
+ end
65
+
66
+ describe ".find!" do
67
+ include_examples "adapter read and load instance with bang", :find!
68
+ end
69
+
70
+ describe ".get_multiple" do
71
+ include_examples "adapter read_multiple and load instances", :get_multiple
72
+ end
73
+
74
+ describe ".read_multiple" do
75
+ include_examples "adapter read_multiple and load instances", :read_multiple
76
+ end
77
+
78
+ describe ".find_multiple" do
79
+ include_examples "adapter read_multiple and load instances", :find_multiple
80
+ end
81
+
46
82
  describe ".get_multi" do
47
- it "returns array of documents" do
48
- john = User.create(:name => 'John')
49
- steve = User.create(:name => 'Steve')
50
- User.get_multi(john.id, steve.id, 'foo').should == {
51
- john.id => john,
52
- steve.id => steve,
53
- 'foo' => nil,
54
- }
55
- end
83
+ include_examples "adapter read_multiple and load instances", :get_multi
56
84
  end
57
85
 
58
86
  describe ".get_or_new" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toystore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-07 00:00:00.000000000 Z
13
+ date: 2012-11-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: adapter
@@ -128,8 +128,10 @@ files:
128
128
  - lib/toy/extensions/set.rb
129
129
  - lib/toy/extensions/string.rb
130
130
  - lib/toy/extensions/time.rb
131
+ - lib/toy/extensions/uuid.rb
131
132
  - lib/toy/identity.rb
132
133
  - lib/toy/identity/abstract_key_factory.rb
134
+ - lib/toy/identity/native_uuid_key_factory.rb
133
135
  - lib/toy/identity/uuid_key_factory.rb
134
136
  - lib/toy/identity_map.rb
135
137
  - lib/toy/inheritance.rb
@@ -183,7 +185,9 @@ files:
183
185
  - spec/toy/extensions/set_spec.rb
184
186
  - spec/toy/extensions/string_spec.rb
185
187
  - spec/toy/extensions/time_spec.rb
188
+ - spec/toy/extensions/uuid_spec.rb
186
189
  - spec/toy/identity/abstract_key_factory_spec.rb
190
+ - spec/toy/identity/native_uuid_key_factory_spec.rb
187
191
  - spec/toy/identity/uuid_key_factory_spec.rb
188
192
  - spec/toy/identity_map_spec.rb
189
193
  - spec/toy/identity_spec.rb
@@ -221,7 +225,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
225
  version: '0'
222
226
  segments:
223
227
  - 0
224
- hash: 1432731575283282863
228
+ hash: -1651404938588113
225
229
  required_rubygems_version: !ruby/object:Gem::Requirement
226
230
  none: false
227
231
  requirements:
@@ -230,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
234
  version: '0'
231
235
  segments:
232
236
  - 0
233
- hash: 1432731575283282863
237
+ hash: -1651404938588113
234
238
  requirements: []
235
239
  rubyforge_project:
236
240
  rubygems_version: 1.8.23
@@ -265,7 +269,9 @@ test_files:
265
269
  - spec/toy/extensions/set_spec.rb
266
270
  - spec/toy/extensions/string_spec.rb
267
271
  - spec/toy/extensions/time_spec.rb
272
+ - spec/toy/extensions/uuid_spec.rb
268
273
  - spec/toy/identity/abstract_key_factory_spec.rb
274
+ - spec/toy/identity/native_uuid_key_factory_spec.rb
269
275
  - spec/toy/identity/uuid_key_factory_spec.rb
270
276
  - spec/toy/identity_map_spec.rb
271
277
  - spec/toy/identity_spec.rb