Module: Garner::Config
Instance Attribute Summary collapse
-
#defaults ⇒ Object
Default configuration settings.
-
#settings ⇒ Object
Current configuration settings.
Instance Method Summary collapse
-
#cache ⇒ Cache
Returns the cache, or defaults to Rails cache when running in Rails or an instance of ActiveSupport::Cache::MemoryStore otherwise.
-
#cache=(cache) ⇒ Cache
Sets the cache to use.
-
#default_cache ⇒ Cache
Returns the default cache store, either Rails.cache or an instance of ActiveSupport::Cache::MemoryStore.
-
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
-
#reset! ⇒ Object
Reset the configuration options to the defaults.
Instance Attribute Details
#defaults ⇒ Object
Default configuration settings.
26 27 28 |
# File 'lib/garner/config.rb', line 26 def defaults @defaults end |
#settings ⇒ Object
Current configuration settings.
23 24 25 |
# File 'lib/garner/config.rb', line 23 def settings @settings end |
Instance Method Details
#cache ⇒ Cache
Returns the cache, or defaults to Rails cache when running in Rails or an instance of ActiveSupport::Cache::MemoryStore otherwise.
74 75 76 77 |
# File 'lib/garner/config.rb', line 74 def cache settings[:cache] = default_cache unless settings.has_key?(:cache) settings[:cache] end |
#cache=(cache) ⇒ Cache
Sets the cache to use.
85 86 87 |
# File 'lib/garner/config.rb', line 85 def cache=(cache) settings[:cache] = cache end |
#default_cache ⇒ Cache
Returns the default cache store, either Rails.cache or an instance of ActiveSupport::Cache::MemoryStore.
64 65 66 |
# File 'lib/garner/config.rb', line 64 def default_cache defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ::ActiveSupport::Cache::MemoryStore.new end |
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/garner/config.rb', line 40 def option(name, = {}) defaults[name] = settings[name] = [: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! ⇒ Object
Reset the configuration options to the defaults.
93 94 95 |
# File 'lib/garner/config.rb', line 93 def reset! settings.replace(defaults) end |