module Garner::Config
Attributes
Default configuration settings.
Current configuration settings.
Public Instance Methods
Returns the cache, or defaults to Rails cache when running in Rails or an instance of ActiveSupport::Cache::MemoryStore otherwise.
@example Get the cache.
config.cache
@return [Cache] The configured cache or a default cache instance.
# File lib/garner/config.rb, line 78 def cache settings[:cache] = default_cache unless settings.key?(:cache) settings[:cache] end
Sets the cache to use.
@example Set the cache.
config.cache = Rails.cache
@return [Cache] The newly set cache.
# File lib/garner/config.rb, line 89 def cache=(cache) settings[:cache] = cache end
Returns the manually configured caller_root
, or a default.
@return [String] The configured caller_root
or a default.
# File lib/garner/config.rb, line 104 def caller_root settings[:caller_root] = default_caller_root unless settings.key?(:caller_root) settings[:caller_root] end
Sets the caller_root
to use.
@return [String] The newly set caller_root.
# File lib/garner/config.rb, line 112 def caller_root=(caller_root) settings[:caller_root] = caller_root && caller_root.to_s end
Returns the default cache store, either Rails.cache or an instance of ActiveSupport::Cache::MemoryStore.
@example Get the default cache store
config.default_cache
@return [Cache] The default cache store instance.
# File lib/garner/config.rb, line 63 def default_cache if defined?(Rails) && Rails.respond_to?(:cache) Rails.cache else ::ActiveSupport::Cache::MemoryStore.new end end
Returns the default caller root, as determined by Garner::Strategies::Context::Key::Caller
.
@return [String] The default caller_root
path.
# File lib/garner/config.rb, line 97 def default_caller_root Garner::Strategies::Context::Key::Caller.default_root end
Define a configuration option with a default.
@example Define the option.
Config.option(:cache, :default => nil)
@param [Symbol] name The name of the configuration option. @param [Hash] options Extras for the option.
@option options [Object] :default The default value.
# File lib/garner/config.rb, line 38 def option(name, options = {}) defaults[name] = settings[name] = options[:default] class_eval <<-RUBY def #{name} settings[#{name.inspect}] end def #{name}=(value) settings[#{name.inspect}] = value end def #{name}? #{name} end RUBY end
Reset the configuration options to the defaults.
@example Reset the configuration options.
config.reset!
# File lib/garner/config.rb, line 120 def reset! settings.replace(defaults) end
# File lib/garner/config.rb, line 133 def whiny_nils? whiny_nils end