Skip to content

Commit

Permalink
Adds default options
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neighman committed Jun 21, 2008
1 parent 834fb68 commit 23c05e4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
17 changes: 10 additions & 7 deletions lib/merb-cache/cache_store.rb
Expand Up @@ -13,13 +13,8 @@ def initialize valid_config={}
end
end

DEFAULT_CONFIG = {
:store => "memcached",
:host => "127.0.0.1:11211"
}.freeze

def initialize
@config = DEFAULT_CONFIG.merge(Merb::Plugins.config[:merb_cache] || {})
def initialize(options = {})
@config = self.class.merge(Merb::Plugins.config[:merb_cache] || {})
unless @config[:disabled]
load
else
Expand All @@ -36,6 +31,13 @@ def cached? key
@store.cached?(key)
end

def self.default_config
@default_config ||= {
:store => "memcached",
:host => "127.0.0.1:11211"
}.freeze
end

private
# Require the cache store

Expand All @@ -46,4 +48,5 @@ def load
rescue LoadError
raise NotFound, @config[:store]
end

end
20 changes: 10 additions & 10 deletions lib/merb-cache/cache_stores/memcached_store.rb
@@ -1,21 +1,21 @@
class Merb::Cache::MemcachedStore < Merb::Cache::Store

def self.valid_config_example
@valid_config_example ||= {
:store => "memcached",
:host => "127.0.0.1:11211"
}
end

class NoClient < StandardError
def initialize
super "No ruby memcached client was available"
end
end

def self.default_config
@default_config ||= {
:store => "memcached",
:host => "127.0.0.1:11211"
}.freeze
end

def initialize(config)
@config = config
connect
@config = self.class.merge(config)
connect!
end

def get(key)
Expand All @@ -37,7 +37,7 @@ def cached?(key)
end

private
def connect
def connect!
@memcache = Memcached.new(@config[:host])
rescue NameError
raise NoClient
Expand Down
18 changes: 9 additions & 9 deletions lib/merb-cache/cache_stores/mintcache_store.rb
@@ -1,20 +1,20 @@
class Merb::Cache::MintcachedStore < Merb::Cache::Store

def self.valid_config_example
@valid_config_example ||= {
:store => "memcached",
:host => "127.0.0.1:11211"
}
end

class NoClient < StandardError
def initialize
super "No ruby memcached client was available"
end
end

def initialize config
@config = config
def self.default_config
@default_config ||= {
:store => "memcached",
:host => "127.0.0.1:11211"
}.freeze
end

def initialize(config)
@config = self.class.merge(config)
connect
end

Expand Down
2 changes: 1 addition & 1 deletion spec/memcached_spec.rb
Expand Up @@ -7,7 +7,7 @@
end

it "should respond to connect" do
@store.private_methods.should include("connect")
@store.private_methods.should include("connect!")
end

it "should respond to put" do
Expand Down
14 changes: 8 additions & 6 deletions spec/merb_cache_spec.rb
Expand Up @@ -14,14 +14,16 @@
lambda { Merb::Cache::Store.new }.should raise_error(Merb::Cache::Store::NotFound)
end

it "should raise Merb::Cache::Store::BadConfiguration when a invalid config is used" # do
# Merb::Plugins.config[:merb_cache] = {
# :fail => 'badconfigoptions'
# }
# lambda { Merb::Cache::Store.new }.should raise_error Merb::Cache::Store::BadConfiguration
# end
it "should merge the default options when the default options are missing" do
Merb::Plugins.config[:merb_cache] = {
:fail => 'badconfigoptions'
}


end
end


describe "returned caches" do
it "should return the format it was stored in"
it "should only cache 200 responses"
Expand Down

0 comments on commit 23c05e4

Please sign in to comment.