toystore 0.10.4 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -85,7 +85,7 @@ pp person.role # "guest"
85
85
 
86
86
  # Querying
87
87
  pp Person.get(john.id)
88
- pp Person.get_multi(john.id)
88
+ pp Person.get_multiple(john.id)
89
89
  pp Person.get('NOT HERE') # nil
90
90
  pp Person.get_or_new('NOT HERE') # new person with id of 'NOT HERE'
91
91
 
@@ -34,7 +34,7 @@ pp person.role # "guest"
34
34
 
35
35
  # Querying
36
36
  pp Person.get(john.id)
37
- pp Person.get_multi(john.id)
37
+ pp Person.get_multiple(john.id)
38
38
  pp Person.get('NOT HERE') # nil
39
39
  pp Person.get_or_new('NOT HERE') # new person with id of 'NOT HERE'
40
40
 
@@ -1,7 +1,6 @@
1
1
  module Toy
2
2
  module Callbacks
3
3
  extend ActiveSupport::Concern
4
- include ActiveSupport::Callbacks
5
4
 
6
5
  included do
7
6
  extend ActiveModel::Callbacks
@@ -26,4 +25,4 @@ module Toy
26
25
  run_callbacks(:update) { super }
27
26
  end
28
27
  end
29
- end
28
+ end
@@ -1,5 +1,4 @@
1
1
  module Toy
2
-
3
2
  module IdentityMap
4
3
  extend ActiveSupport::Concern
5
4
 
@@ -79,4 +78,4 @@ module Toy
79
78
  IdentityMap.repository.delete(id) if IdentityMap.enabled?
80
79
  end
81
80
  end
82
- end
81
+ end
@@ -1,19 +1,18 @@
1
1
  module Toy
2
2
  module Object
3
3
  extend ActiveSupport::Concern
4
+ extend ActiveModel::Naming
5
+ include ActiveModel::Conversion
6
+ include ActiveModel::Validations
4
7
 
5
- included do
6
- extend ActiveModel::Naming
7
- include ActiveModel::Conversion
8
- include Attributes
9
- include Cloneable
10
- include Dirty
11
- include Equality
12
- include Inspect
13
- include Logger
14
- include Inheritance
15
- include Serialization
16
- end
8
+ include Attributes
9
+ include Cloneable
10
+ include Dirty
11
+ include Equality
12
+ include Inspect
13
+ include Logger
14
+ include Inheritance
15
+ include Serialization
17
16
 
18
17
  def persisted?
19
18
  false
@@ -73,7 +73,7 @@ module Toy
73
73
 
74
74
  def find_target
75
75
  return [] if target_ids.blank?
76
- proxy_class.get_multi(target_ids)
76
+ proxy_class.get_multiple(target_ids).values
77
77
  end
78
78
 
79
79
  def target_ids
@@ -95,4 +95,4 @@ module Toy
95
95
  end
96
96
  end
97
97
  end
98
- end
98
+ end
@@ -13,10 +13,16 @@ module Toy
13
13
  get(id) || raise(Toy::NotFound.new(id))
14
14
  end
15
15
 
16
- def get_multi(*ids)
17
- ids.flatten.map { |id| get(id) }
16
+ def get_multiple(*ids)
17
+ result = adapter.read_multiple(*ids.flatten)
18
+ result.each do |id, attrs|
19
+ result[id] = attrs.nil? ? nil : load(id, attrs)
20
+ end
21
+ result
18
22
  end
19
23
 
24
+ alias_method :get_multi, :get_multiple
25
+
20
26
  def get_or_new(id)
21
27
  get(id) || new(:id => id)
22
28
  end
@@ -1,5 +1,7 @@
1
1
  module Toy
2
2
  module Reloadable
3
+ extend ActiveSupport::Concern
4
+
3
5
  def reload
4
6
  if attrs = adapter.read(id)
5
7
  attrs['id'] = id
@@ -3,24 +3,22 @@ module Toy
3
3
  extend ActiveSupport::Concern
4
4
  extend Plugins
5
5
 
6
- included do
7
- include Toy::Object
8
- include Persistence
9
- include MassAssignmentSecurity
10
- include DirtyStore
11
- include Querying
12
- include Reloadable
6
+ include Toy::Object
7
+ include Persistence
8
+ include MassAssignmentSecurity
9
+ include DirtyStore
10
+ include Querying
11
+ include Reloadable
13
12
 
14
- include Callbacks
15
- include Validations
16
- include Timestamps
13
+ include Callbacks
14
+ include Validations
15
+ include Timestamps
17
16
 
18
- include Lists
19
- include References
20
- include AssociationSerialization
17
+ include Lists
18
+ include References
19
+ include AssociationSerialization
21
20
 
22
- include IdentityMap
23
- include Caching
24
- end
21
+ include IdentityMap
22
+ include Caching
25
23
  end
26
24
  end
@@ -27,4 +27,4 @@ module Toy
27
27
  save || raise(RecordInvalid.new(self))
28
28
  end
29
29
  end
30
- end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Toy
2
- VERSION = "0.10.4"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -18,6 +18,7 @@ require 'support/constants'
18
18
  require 'support/objects'
19
19
  require 'support/identity_map_matcher'
20
20
  require 'support/name_and_number_key_factory'
21
+ require 'support/shared_active_model_lint'
21
22
 
22
23
  Logger.new(log_path.join('test.log')).tap do |log|
23
24
  Toy.logger = log
@@ -0,0 +1,15 @@
1
+ require "active_model/lint"
2
+ require "test/unit/assertions"
3
+
4
+ shared_examples_for 'ActiveModel' do
5
+ include ActiveModel::Lint::Tests
6
+ include Test::Unit::Assertions
7
+
8
+ before { @model = subject }
9
+
10
+ ActiveModel::Lint::Tests.public_instance_methods.map(&:to_s).grep(/^test/).each do |test|
11
+ example test.gsub("_", " ") do
12
+ send test
13
+ end
14
+ end
15
+ end
@@ -93,14 +93,14 @@ describe Toy::List do
93
93
 
94
94
  it "memoizes result" do
95
95
  @user.games.should == [@game]
96
- Game.should_not_receive(:get_multi)
96
+ Game.should_not_receive(:get_multiple)
97
97
  Game.should_not_receive(:get)
98
98
  @user.games.should == [@game]
99
99
  end
100
100
 
101
101
  it "does not query if ids attribute is blank" do
102
102
  user = User.create
103
- Game.should_not_receive(:get_multi)
103
+ Game.should_not_receive(:get_multiple)
104
104
  Game.should_not_receive(:get)
105
105
  user.games.should == []
106
106
  end
@@ -132,19 +132,19 @@ describe Toy::List do
132
132
  end
133
133
 
134
134
  it "unmemoizes the list" do
135
- games = [@game]
136
- @user.games.should == games
135
+ games = {@game.id => @game}
136
+ @user.games.should == games.values
137
137
  @user.games.reset
138
- Game.should_receive(:get_multi).and_return(games)
139
- @user.games.should == games
138
+ Game.should_receive(:get_multiple).and_return(games)
139
+ @user.games.should == games.values
140
140
  end
141
141
 
142
142
  it "should be reset when owner is reloaded" do
143
- games = [@game]
144
- @user.games.should == games
143
+ games = {@game.id => @game}
144
+ @user.games.should == games.values
145
145
  @user.reload
146
- Game.should_receive(:get_multi).and_return(games)
147
- @user.games.should == games
146
+ Game.should_receive(:get_multiple).and_return(games)
147
+ @user.games.should == games.values
148
148
  end
149
149
  end
150
150
 
@@ -3,6 +3,10 @@ require 'helper'
3
3
  describe Toy::Object do
4
4
  uses_objects('User')
5
5
 
6
+ subject { User.new }
7
+
8
+ it_should_behave_like 'ActiveModel'
9
+
6
10
  it "adds model naming" do
7
11
  model_name = User.model_name
8
12
  model_name.should == 'User'
@@ -31,11 +31,27 @@ describe Toy::Querying do
31
31
  end
32
32
  end
33
33
 
34
+ describe ".get_multiple" do
35
+ it "returns Hash of ids pointed at result" do
36
+ john = User.create(:name => 'John')
37
+ steve = User.create(:name => 'Steve')
38
+ User.get_multiple(john.id, steve.id, 'foo').should == {
39
+ john.id => john,
40
+ steve.id => steve,
41
+ 'foo' => nil,
42
+ }
43
+ end
44
+ end
45
+
34
46
  describe ".get_multi" do
35
47
  it "returns array of documents" do
36
48
  john = User.create(:name => 'John')
37
49
  steve = User.create(:name => 'Steve')
38
- User.get_multi(john.id, steve.id).should == [john, steve]
50
+ User.get_multi(john.id, steve.id, 'foo').should == {
51
+ john.id => john,
52
+ steve.id => steve,
53
+ 'foo' => nil,
54
+ }
39
55
  end
40
56
  end
41
57
 
@@ -3,6 +3,10 @@ require 'helper'
3
3
  describe Toy::Store do
4
4
  uses_constants('User')
5
5
 
6
+ subject { User.new }
7
+
8
+ it_should_behave_like 'ActiveModel'
9
+
6
10
  describe "#to_key" do
7
11
  it "returns [id] if persisted" do
8
12
  user = User.create
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency 'adapter', '~> 0.5.1'
20
+ s.add_dependency 'adapter', '~> 0.6.0'
21
21
  s.add_dependency 'activemodel', '~> 3.0'
22
22
  s.add_dependency 'activesupport', '~> 3.0'
23
23
  s.add_dependency 'simple_uuid', '~> 0.2'
metadata CHANGED
@@ -1,96 +1,89 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: toystore
3
- version: !ruby/object:Gem::Version
4
- hash: 63
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 10
9
- - 4
10
- version: 0.10.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Geoffrey Dagley
14
9
  - John Nunemaker
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2012-10-29 00:00:00 -04:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
23
- requirement: &id001 !ruby/object:Gem::Requirement
13
+ date: 2012-11-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: adapter
17
+ requirement: !ruby/object:Gem::Requirement
24
18
  none: false
25
- requirements:
19
+ requirements:
26
20
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 9
29
- segments:
30
- - 0
31
- - 5
32
- - 1
33
- version: 0.5.1
34
- version_requirements: *id001
35
- name: adapter
36
- prerelease: false
21
+ - !ruby/object:Gem::Version
22
+ version: 0.6.0
37
23
  type: :runtime
38
- - !ruby/object:Gem::Dependency
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
40
26
  none: false
41
- requirements:
27
+ requirements:
42
28
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 7
45
- segments:
46
- - 3
47
- - 0
48
- version: "3.0"
49
- version_requirements: *id002
29
+ - !ruby/object:Gem::Version
30
+ version: 0.6.0
31
+ - !ruby/object:Gem::Dependency
50
32
  name: activemodel
51
- prerelease: false
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '3.0'
52
39
  type: :runtime
53
- - !ruby/object:Gem::Dependency
54
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
55
42
  none: false
56
- requirements:
43
+ requirements:
57
44
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 7
60
- segments:
61
- - 3
62
- - 0
63
- version: "3.0"
64
- version_requirements: *id003
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ - !ruby/object:Gem::Dependency
65
48
  name: activesupport
66
- prerelease: false
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
67
55
  type: :runtime
68
- - !ruby/object:Gem::Dependency
69
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
70
58
  none: false
71
- requirements:
59
+ requirements:
72
60
  - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 15
75
- segments:
76
- - 0
77
- - 2
78
- version: "0.2"
79
- version_requirements: *id004
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ - !ruby/object:Gem::Dependency
80
64
  name: simple_uuid
81
- prerelease: false
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '0.2'
82
71
  type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '0.2'
83
79
  description: An object mapper for anything that can read, write and delete data
84
- email:
80
+ email:
85
81
  - gdagley@gmail.com
86
82
  - nunemaker@gmail.com
87
83
  executables: []
88
-
89
84
  extensions: []
90
-
91
85
  extra_rdoc_files: []
92
-
93
- files:
86
+ files:
94
87
  - .gitignore
95
88
  - .rspec
96
89
  - .travis.yml
@@ -169,6 +162,7 @@ files:
169
162
  - spec/support/identity_map_matcher.rb
170
163
  - spec/support/name_and_number_key_factory.rb
171
164
  - spec/support/objects.rb
165
+ - spec/support/shared_active_model_lint.rb
172
166
  - spec/toy/association_serialization_spec.rb
173
167
  - spec/toy/attribute_spec.rb
174
168
  - spec/toy/attributes_spec.rb
@@ -212,49 +206,45 @@ files:
212
206
  - spec/toy/timestamps_spec.rb
213
207
  - spec/toy/validations_spec.rb
214
208
  - spec/toy_spec.rb
215
- - test/lint_test.rb
216
209
  - toystore.gemspec
217
- has_rdoc: true
218
210
  homepage: http://jnunemaker.github.com/toystore/
219
211
  licenses: []
220
-
221
212
  post_install_message:
222
213
  rdoc_options: []
223
-
224
- require_paths:
214
+ require_paths:
225
215
  - lib
226
- required_ruby_version: !ruby/object:Gem::Requirement
216
+ required_ruby_version: !ruby/object:Gem::Requirement
227
217
  none: false
228
- requirements:
229
- - - ">="
230
- - !ruby/object:Gem::Version
231
- hash: 3
232
- segments:
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ segments:
233
223
  - 0
234
- version: "0"
235
- required_rubygems_version: !ruby/object:Gem::Requirement
224
+ hash: 1432731575283282863
225
+ required_rubygems_version: !ruby/object:Gem::Requirement
236
226
  none: false
237
- requirements:
238
- - - ">="
239
- - !ruby/object:Gem::Version
240
- hash: 3
241
- segments:
227
+ requirements:
228
+ - - ! '>='
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ segments:
242
232
  - 0
243
- version: "0"
233
+ hash: 1432731575283282863
244
234
  requirements: []
245
-
246
235
  rubyforge_project:
247
- rubygems_version: 1.6.2
236
+ rubygems_version: 1.8.23
248
237
  signing_key:
249
238
  specification_version: 3
250
239
  summary: An object mapper for anything that can read, write and delete data
251
- test_files:
240
+ test_files:
252
241
  - spec/helper.rb
253
242
  - spec/spec.opts
254
243
  - spec/support/constants.rb
255
244
  - spec/support/identity_map_matcher.rb
256
245
  - spec/support/name_and_number_key_factory.rb
257
246
  - spec/support/objects.rb
247
+ - spec/support/shared_active_model_lint.rb
258
248
  - spec/toy/association_serialization_spec.rb
259
249
  - spec/toy/attribute_spec.rb
260
250
  - spec/toy/attributes_spec.rb
@@ -298,4 +288,3 @@ test_files:
298
288
  - spec/toy/timestamps_spec.rb
299
289
  - spec/toy/validations_spec.rb
300
290
  - spec/toy_spec.rb
301
- - test/lint_test.rb
@@ -1,40 +0,0 @@
1
- require 'bundler/setup'
2
- require 'pathname'
3
-
4
- root_path = Pathname(__FILE__).dirname.join('..').expand_path
5
- lib_path = root_path.join('lib')
6
-
7
- $:.unshift(lib_path)
8
-
9
- require 'toy'
10
-
11
- Adapter.define(:memory) do
12
- def read(key)
13
- deserialize(client[key_for(key)])
14
- end
15
-
16
- def write(key, value)
17
- client[key_for(key)] = serialize(value)
18
- end
19
-
20
- def delete(key)
21
- client.delete(key_for(key))
22
- end
23
-
24
- def clear
25
- client.clear
26
- end
27
- end
28
-
29
- class User
30
- include Toy::Store
31
- adapter :memory, {}
32
- end
33
-
34
- class LintTest < ActiveModel::TestCase
35
- include ActiveModel::Lint::Tests
36
-
37
- def setup
38
- @model = User.new
39
- end
40
- end