toystore 0.6.2 → 0.6.3

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.
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ group(:development) do
7
7
  gem 'timecop', '~> 0.3.5'
8
8
  gem 'tzinfo', '~> 0.3.23'
9
9
  gem 'log_buddy', '~> 0.5.0'
10
+ gem 'rack-test'
10
11
 
11
12
  gem 'bson'
12
13
  gem 'bson_ext'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- toystore (0.6.1)
4
+ toystore (0.6.3)
5
5
  activemodel (~> 3.0.3)
6
6
  activesupport (~> 3.0.3)
7
7
  adapter (~> 0.5.1)
@@ -22,6 +22,9 @@ GEM
22
22
  diff-lcs (1.1.2)
23
23
  i18n (0.5.0)
24
24
  log_buddy (0.5.0)
25
+ rack (1.2.1)
26
+ rack-test (0.5.7)
27
+ rack (>= 1.0)
25
28
  rake (0.8.7)
26
29
  rspec (2.4.0)
27
30
  rspec-core (~> 2.4.0)
@@ -45,6 +48,7 @@ DEPENDENCIES
45
48
  bson
46
49
  bson_ext
47
50
  log_buddy (~> 0.5.0)
51
+ rack-test
48
52
  rake (~> 0.8.7)
49
53
  rspec (~> 2.3)
50
54
  simple_uuid (~> 0.1.1)
data/README.rdoc CHANGED
@@ -2,7 +2,17 @@
2
2
 
3
3
  An object mapper for anything that can read, write and delete data.
4
4
 
5
- See examples/models.rb for potential direction. The idea is that any key-value store (via adapters) that supports read, write, delete will work (memcache, membase, redis, couch, toyko. Potentially even RESTFUL services or sqlite with a single key-value table?)
5
+ See examples/ for potential direction. The idea is that any key-value store (via adapters) that supports read, write, delete will work (memcache, membase, mongo, redis, couch, toyko. Potentially even RESTFUL services or sqlite with a single key-value table?)
6
+
7
+ == Identity Map
8
+
9
+ By default, Toystore has identity map turned on. It assumes that any Toystore model has a unique id across all models. This means you either need to use the default uuid id's, object_id's (included), some other unique id, or create your own key factory that namespaces to model (see examples).
10
+
11
+ You also need to clear the map before each request. For this, there is a provided piece of middleware that you can use.
12
+
13
+ use(Toy::Middleware::IdentityMap)
14
+
15
+ It is autoloaded, so just add it to your config.ru or sinatra/rails app as you would any other middleware and you are good to go.
6
16
 
7
17
  == Note on Patches/Pull Requests
8
18
 
data/lib/toy.rb CHANGED
@@ -43,6 +43,10 @@ module Toy
43
43
  model.identity_map.clear if model.identity_map_on?
44
44
  end
45
45
  end
46
+
47
+ module Middleware
48
+ autoload 'IdentityMap', 'toy/middleware/identity_map'
49
+ end
46
50
  end
47
51
 
48
52
  require 'toy/exceptions'
@@ -0,0 +1,16 @@
1
+ module Toy
2
+ module Middleware
3
+ class IdentityMap
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ Toy.identity_map.clear
10
+ @app.call(env)
11
+ ensure
12
+ Toy.identity_map.clear
13
+ end
14
+ end
15
+ end
16
+ end
data/lib/toy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Toy
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+ require 'rack/test'
3
+
4
+ describe Toy::Middleware::IdentityMap do
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ @app ||= Rack::Builder.new do
9
+ use Toy::Middleware::IdentityMap
10
+ map "/" do
11
+ run lambda {|env| [200, {}, []] }
12
+ end
13
+ map "/fail" do
14
+ run lambda {|env| raise "FAIL!" }
15
+ end
16
+ end.to_app
17
+ end
18
+
19
+ context "with a successful request" do
20
+ it "clear the identity map" do
21
+ Toy.identity_map.should_receive(:clear).twice
22
+ get '/'
23
+ end
24
+ end
25
+
26
+ context "when the request raises an error" do
27
+ it "clear the identity map" do
28
+ Toy.identity_map.should_receive(:clear).twice
29
+ get '/fail' rescue nil
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toystore
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 1
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 6
8
- - 2
9
- version: 0.6.2
9
+ - 3
10
+ version: 0.6.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Geoffrey Dagley
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-02-04 00:00:00 -05:00
19
+ date: 2011-02-05 00:00:00 -05:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -26,6 +27,7 @@ dependencies:
26
27
  requirements:
27
28
  - - ~>
28
29
  - !ruby/object:Gem::Version
30
+ hash: 9
29
31
  segments:
30
32
  - 0
31
33
  - 5
@@ -41,6 +43,7 @@ dependencies:
41
43
  requirements:
42
44
  - - ~>
43
45
  - !ruby/object:Gem::Version
46
+ hash: 1
44
47
  segments:
45
48
  - 3
46
49
  - 0
@@ -56,6 +59,7 @@ dependencies:
56
59
  requirements:
57
60
  - - ~>
58
61
  - !ruby/object:Gem::Version
62
+ hash: 1
59
63
  segments:
60
64
  - 3
61
65
  - 0
@@ -71,6 +75,7 @@ dependencies:
71
75
  requirements:
72
76
  - - ~>
73
77
  - !ruby/object:Gem::Version
78
+ hash: 25
74
79
  segments:
75
80
  - 0
76
81
  - 1
@@ -142,6 +147,7 @@ files:
142
147
  - lib/toy/lists.rb
143
148
  - lib/toy/logger.rb
144
149
  - lib/toy/mass_assignment_security.rb
150
+ - lib/toy/middleware/identity_map.rb
145
151
  - lib/toy/persistence.rb
146
152
  - lib/toy/plugins.rb
147
153
  - lib/toy/proxies/embedded_list.rb
@@ -194,6 +200,7 @@ files:
194
200
  - spec/toy/lists_spec.rb
195
201
  - spec/toy/logger_spec.rb
196
202
  - spec/toy/mass_assignment_security_spec.rb
203
+ - spec/toy/middleware/identity_map_spec.rb
197
204
  - spec/toy/persistence_spec.rb
198
205
  - spec/toy/plugins_spec.rb
199
206
  - spec/toy/querying_spec.rb
@@ -221,6 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
228
  requirements:
222
229
  - - ">="
223
230
  - !ruby/object:Gem::Version
231
+ hash: 3
224
232
  segments:
225
233
  - 0
226
234
  version: "0"
@@ -229,6 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
237
  requirements:
230
238
  - - ">="
231
239
  - !ruby/object:Gem::Version
240
+ hash: 3
232
241
  segments:
233
242
  - 0
234
243
  version: "0"
@@ -278,6 +287,7 @@ test_files:
278
287
  - spec/toy/lists_spec.rb
279
288
  - spec/toy/logger_spec.rb
280
289
  - spec/toy/mass_assignment_security_spec.rb
290
+ - spec/toy/middleware/identity_map_spec.rb
281
291
  - spec/toy/persistence_spec.rb
282
292
  - spec/toy/plugins_spec.rb
283
293
  - spec/toy/querying_spec.rb