soveran-drawer 0.0.5 → 0.0.7

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/README.rdoc CHANGED
@@ -30,9 +30,5 @@ be used for retrieving and saving the cached contents.
30
30
  $ gem sources -a http://gems.github.com (you only have to do this once)
31
31
  $ sudo gem install soveran-drawer
32
32
 
33
- == Contributors
34
-
35
- Michel Martens
36
-
37
33
  Copyright (c) 2008 Michel Martens.
38
34
  Released under the MIT license.
data/lib/drawer.rb CHANGED
@@ -26,7 +26,7 @@ class Drawer
26
26
  end
27
27
 
28
28
  def get(k)
29
- cache[k]
29
+ cache[k] or (set(k, yield) if block_given?)
30
30
  end
31
31
 
32
32
  def get_multi(*ks)
data/test/drawer_test.rb CHANGED
@@ -20,9 +20,16 @@ class TestDrawer < Test::Unit::TestCase
20
20
  assert_nil @drawer.get("foo")
21
21
  end
22
22
 
23
+ should "set a key with a block on a cache miss" do
24
+ assert_equal 123, @drawer.get("foo") { 123 }
25
+ assert_nothing_raised { @drawer.get("foo") { raise 'Should not call block.' } }
26
+ end
27
+
23
28
  should "successfully set a key" do
24
29
  @drawer.set("foo", 123)
25
30
  assert_equal 123, @drawer.get("foo")
31
+
32
+ assert_equal 124, @drawer.set("foo", 124)
26
33
  end
27
34
 
28
35
  should "clear an entry with remove" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soveran-drawer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
@@ -63,6 +63,6 @@ rubyforge_project:
63
63
  rubygems_version: 1.2.0
64
64
  signing_key:
65
65
  specification_version: 2
66
- summary: Ultra light cache.
66
+ summary: Ultra light file-based cache.
67
67
  test_files: []
68
68