adapter 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -52,8 +52,4 @@ Adapters can be defined using a block, a module, or a module and a block. This a
52
52
  * Make your feature addition or bug fix.
53
53
  * Add tests for it. This is important so we don't break it in a future version unintentionally.
54
54
  * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine, but bump version in a commit by itself so we can ignore when we pull)
55
- * Send us a pull request. Bonus points for topic branches.
56
-
57
- == Copyright
58
-
59
- Copyright (c) 2010 New Toy. See LICENSE for details.
55
+ * Send us a pull request. Bonus points for topic branches.
@@ -2,9 +2,8 @@ module Adapter
2
2
  module Defaults
3
3
  def fetch(key, value=nil, &block)
4
4
  read(key) || begin
5
- value = yield(key) if value.nil? && block_given?
6
- write(key, value)
7
- value
5
+ value = block_given? ? yield(key) : value
6
+ read(key) || value
8
7
  end
9
8
  end
10
9
 
@@ -1,3 +1,3 @@
1
1
  module Adapter
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
@@ -195,12 +195,12 @@ describe Adapter do
195
195
  end
196
196
 
197
197
  describe "#fetch" do
198
- it "returns value if found" do
198
+ it "returns value if key found" do
199
199
  adapter.write('foo', 'bar')
200
200
  adapter.fetch('foo', 'baz').should == 'bar'
201
201
  end
202
202
 
203
- it "returns value if not found" do
203
+ it "returns default value if not key found" do
204
204
  adapter.fetch('foo', 'baz').should == 'baz'
205
205
  end
206
206
 
@@ -213,11 +213,20 @@ describe Adapter do
213
213
  end.should == 'bar'
214
214
  end
215
215
 
216
- it "returns result of block if key not found and writes result to key" do
216
+ it "returns default if key not found" do
217
+ adapter.fetch('foo', 'default').should == 'default'
218
+ end
219
+
220
+ it "returns result of block if key not found" do
217
221
  adapter.fetch('foo') do
218
222
  'baz'
219
223
  end.should == 'baz'
220
- adapter.fetch('foo').should == 'baz'
224
+ end
225
+
226
+ it "returns key if result of block writes key" do
227
+ adapter.fetch('foo', 'default') do
228
+ adapter.write('foo', 'write in block')
229
+ end.should == 'write in block'
221
230
  end
222
231
 
223
232
  it "yields key to block" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adapter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 1
10
- version: 0.5.1
9
+ - 2
10
+ version: 0.5.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Nunemaker
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-01-25 00:00:00 -05:00
20
+ date: 2011-01-26 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies: []
23
23