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.
-
#caller_root ⇒ String
Returns the manually configured caller_root, or a default.
-
#caller_root=(caller_root) ⇒ String
Sets the caller_root to use.
-
#default_cache ⇒ Cache
Returns the default cache store, either Rails.cache or an instance of ActiveSupport::Cache::MemoryStore.
-
#default_caller_root ⇒ String
Returns the default caller root, as determined by Garner::Strategies::Context::Key::Caller.
-
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
-
#reset! ⇒ Object
Reset the configuration options to the defaults.
- #whiny_nils? ⇒ Boolean
Instance Attribute Details
#defaults ⇒ Object
Default configuration settings.
24 25 26 |
# File 'lib/garner/config.rb', line 24 def defaults @defaults end |
#settings ⇒ Object
Current configuration settings.
21 22 23 |
# File 'lib/garner/config.rb', line 21 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.
78 79 80 81 |
# File 'lib/garner/config.rb', line 78 def cache settings[:cache] = default_cache unless settings.key?(:cache) settings[:cache] end |
#cache=(cache) ⇒ Cache
Sets the cache to use.
89 90 91 |
# File 'lib/garner/config.rb', line 89 def cache=(cache) settings[:cache] = cache end |
#caller_root ⇒ String
Returns the manually configured caller_root, or a default.
104 105 106 107 |
# 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 |
#caller_root=(caller_root) ⇒ String
Sets the caller_root to use.
112 113 114 |
# File 'lib/garner/config.rb', line 112 def caller_root=(caller_root) settings[:caller_root] = caller_root && caller_root.to_s end |
#default_cache ⇒ Cache
Returns the default cache store, either Rails.cache or an instance of ActiveSupport::Cache::MemoryStore.
63 64 65 66 67 68 69 |
# 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 |
#default_caller_root ⇒ String
Returns the default caller root, as determined by Garner::Strategies::Context::Key::Caller.
97 98 99 |
# File 'lib/garner/config.rb', line 97 def default_caller_root Garner::Strategies::Context::Key::Caller.default_root end |
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/garner/config.rb', line 38 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.
120 121 122 |
# File 'lib/garner/config.rb', line 120 def reset! settings.replace(defaults) end |
#whiny_nils? ⇒ Boolean
133 134 135 |
# File 'lib/garner/config.rb', line 133 def whiny_nils? whiny_nils end |