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 +1 -1
- data/examples/plain_old_object_on_roids.rb +1 -1
- data/lib/toy/callbacks.rb +1 -2
- data/lib/toy/identity_map.rb +1 -2
- data/lib/toy/object.rb +11 -12
- data/lib/toy/proxies/list.rb +2 -2
- data/lib/toy/querying.rb +8 -2
- data/lib/toy/reloadable.rb +2 -0
- data/lib/toy/store.rb +14 -16
- data/lib/toy/validations.rb +1 -1
- data/lib/toy/version.rb +1 -1
- data/spec/helper.rb +1 -0
- data/spec/support/shared_active_model_lint.rb +15 -0
- data/spec/toy/list_spec.rb +10 -10
- data/spec/toy/object_spec.rb +4 -0
- data/spec/toy/querying_spec.rb +17 -1
- data/spec/toy/store_spec.rb +4 -0
- data/toystore.gemspec +1 -1
- metadata +76 -87
- data/test/lint_test.rb +0 -40
data/README.md
CHANGED
data/lib/toy/callbacks.rb
CHANGED
data/lib/toy/identity_map.rb
CHANGED
data/lib/toy/object.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
data/lib/toy/proxies/list.rb
CHANGED
data/lib/toy/querying.rb
CHANGED
@@ -13,10 +13,16 @@ module Toy
|
|
13
13
|
get(id) || raise(Toy::NotFound.new(id))
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
ids.flatten
|
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
|
data/lib/toy/reloadable.rb
CHANGED
data/lib/toy/store.rb
CHANGED
@@ -3,24 +3,22 @@ module Toy
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
extend Plugins
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
13
|
+
include Callbacks
|
14
|
+
include Validations
|
15
|
+
include Timestamps
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
include Lists
|
18
|
+
include References
|
19
|
+
include AssociationSerialization
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
21
|
+
include IdentityMap
|
22
|
+
include Caching
|
25
23
|
end
|
26
24
|
end
|
data/lib/toy/validations.rb
CHANGED
data/lib/toy/version.rb
CHANGED
data/spec/helper.rb
CHANGED
@@ -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
|
data/spec/toy/list_spec.rb
CHANGED
@@ -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(:
|
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(:
|
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 =
|
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(:
|
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 =
|
144
|
-
@user.games.should == games
|
143
|
+
games = {@game.id => @game}
|
144
|
+
@user.games.should == games.values
|
145
145
|
@user.reload
|
146
|
-
Game.should_receive(:
|
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
|
|
data/spec/toy/object_spec.rb
CHANGED
data/spec/toy/querying_spec.rb
CHANGED
@@ -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 ==
|
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
|
|
data/spec/toy/store_spec.rb
CHANGED
data/toystore.gemspec
CHANGED
@@ -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.
|
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
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
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
|
-
|
39
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
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
|
-
|
54
|
-
|
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
|
-
|
60
|
-
|
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
|
-
|
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
|
-
|
69
|
-
|
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
|
-
|
75
|
-
|
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
|
-
|
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
|
-
|
232
|
-
segments:
|
218
|
+
requirements:
|
219
|
+
- - ! '>='
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
segments:
|
233
223
|
- 0
|
234
|
-
|
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
|
-
|
241
|
-
segments:
|
227
|
+
requirements:
|
228
|
+
- - ! '>='
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0'
|
231
|
+
segments:
|
242
232
|
- 0
|
243
|
-
|
233
|
+
hash: 1432731575283282863
|
244
234
|
requirements: []
|
245
|
-
|
246
235
|
rubyforge_project:
|
247
|
-
rubygems_version: 1.
|
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
|
data/test/lint_test.rb
DELETED
@@ -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
|