Permalink
Browse files

Simplify default behavior

  • Loading branch information...
wycats committed May 9, 2009
1 parent f65e168 commit 0f9597ea91cb2829ef792be042e90305f6e467b3
Showing with 20 additions and 62 deletions.
  1. +5 −1 lib/moneta.rb
  2. +0 −4 lib/moneta/berkeley.rb
  3. +0 −4 lib/moneta/couch.rb
  4. +2 −6 lib/moneta/file.rb
  5. +3 −6 lib/moneta/memcache.rb
  6. +4 −11 lib/moneta/rufus.rb
  7. +1 −6 lib/moneta/s3.rb
  8. +0 −5 lib/moneta/sdbm.rb
  9. +4 −10 lib/moneta/tyrant.rb
  10. +1 −9 lib/moneta/xattr.rb
View
@@ -67,6 +67,10 @@ module Defaults
def fetch(key, value = nil)
value ||= block_given? ? yield(key) : default
self[key] || value
- end
+ end
+
+ def store(key, value, options = {})
+ self[key] = value
+ end
end
end
View
@@ -31,10 +31,6 @@ def []=(key,value)
@db[key] = value
end
- def store(key, value, options={})
- @db[key] = value
- end
-
def [](key)
@db[key]
end
View
@@ -45,10 +45,6 @@ def delete(key)
nil
end
- def store(key, value, options = {})
- self[key] = value
- end
-
def update_key(key, options = {})
val = self[key]
self.store(key, val, options)
View
@@ -72,11 +72,7 @@ def delete(key)
value
rescue Errno::ENOENT
end
-
- def store(key, value, options = {})
- self[key] = value
- end
-
+
def clear
FileUtils.rm_rf(@directory)
FileUtils.mkdir(@directory)
@@ -88,8 +84,8 @@ def path(key)
end
end
include Implementation
- include Expires
include Defaults
+ include Expires
end
end
View
@@ -7,6 +7,8 @@
module Moneta
class Memcache
+ include Defaults
+
def initialize(options = {})
@cache = MemCache.new(options.delete(:server), options)
end
@@ -24,12 +26,7 @@ def [](key)
def []=(key, value)
store(key, value)
end
-
- def fetch(key, value = nil)
- value ||= block_given? ? yield(key) : default
- self[key] || value
- end
-
+
def delete(key)
value = self[key]
@cache.delete(key) if value
View
@@ -6,7 +6,9 @@
end
module Moneta
- class BasicRufus < ::Rufus::Tokyo::Cabinet
+ class BasicRufus < ::Rufus::Tokyo::Cabinet
+ include Defaults
+
def initialize(options = {})
file = options[:file]
super("#{file}.tch")
@@ -24,16 +26,7 @@ def [](key)
def []=(key, value)
super(key, Marshal.dump(value))
- end
-
- def fetch(key, value = nil)
- value ||= block_given? ? yield(key) : default
- self[key] || value
- end
-
- def store(key, value, options = {})
- self[key] = value
- end
+ end
end
class Rufus < BasicRufus
View
@@ -55,12 +55,7 @@ def [](key)
def []=(key, value)
store(key, value)
end
-
- def fetch(key, value = nil)
- value ||= block_given? ? yield(key) : default
- self[key] || value
- end
-
+
def delete(key)
k = s3_key(key)
if k
View
@@ -2,7 +2,6 @@
module Moneta
class BasicSDBM < ::SDBM
-
include Defaults
def [](key)
@@ -15,10 +14,6 @@ def []=(key, value)
super(key, Marshal.dump(value))
end
- def store(key, value, options = {})
- self[key] = value
- end
-
def delete(key)
if val = super
Marshal.load(val)
View
@@ -7,6 +7,8 @@
module Moneta
class Tyrant < ::Rufus::Tokyo::Tyrant
+ include Defaults
+
module Implementation
def initialize(options = {})
host = options[:host]
@@ -26,17 +28,9 @@ def [](key)
def []=(key, value)
super(key, Marshal.dump(value))
- end
-
- def fetch(key, value = nil)
- value ||= block_given? ? yield(key) : default
- self[key] || value
- end
-
- def store(key, value, options = {})
- self[key] = value
- end
+ end
end
+
include Implementation
include Expires
View
@@ -8,6 +8,7 @@
module Moneta
class Xattr
+ include Defaults
def initialize(options = {})
file = options[:file]
@@ -37,22 +38,13 @@ def []=(key, value)
@hash.set(key, Marshal.dump(value))
end
- def fetch(key, value = nil)
- value ||= block_given? ? yield(key) : default
- self[key] || value
- end
-
def delete(key)
return nil unless key?(key)
value = self[key]
@hash.remove(key)
value
end
- def store(key, value, options = {})
- self[key] = value
- end
-
def clear
@hash.list.each do |item|
@hash.remove(item)

0 comments on commit 0f9597e

Please sign in to comment.