Module: Mongoid::CachedJson::Config
- Extended by:
- Config
- Includes:
- ActiveSupport::Callbacks
- Included in:
- Config
- Defined in:
- lib/mongoid-cached-json/config.rb
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 under Rails or ActiveSupport::Cache::MemoryStore.
-
#cache=(cache) ⇒ Cache
Sets the cache to use.
-
#default_cache ⇒ Cache
Returns the default cache store, for example Rails cache or an instance of ActiveSupport::Cache::MemoryStore.
-
#default_version ⇒ Version
Returns the default JSON version.
-
#default_version=(default_version) ⇒ Version
Sets the default JSON version.
-
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
-
#reset! ⇒ Object
Reset the configuration options to the defaults.
-
#transform(&block) ⇒ Object
Define a transformation on JSON data.
Instance Attribute Details
#defaults ⇒ Object
Default configuration settings.
12 13 14 |
# File 'lib/mongoid-cached-json/config.rb', line 12 def defaults @defaults end |
#settings ⇒ Object
Current configuration settings.
9 10 11 |
# File 'lib/mongoid-cached-json/config.rb', line 9 def settings @settings end |
Instance Method Details
#cache ⇒ Cache
Returns the cache, or defaults to Rails cache when running under Rails or ActiveSupport::Cache::MemoryStore.
84 85 86 87 |
# File 'lib/mongoid-cached-json/config.rb', line 84 def cache settings[:cache] = default_cache unless settings.has_key?(:cache) settings[:cache] end |
#cache=(cache) ⇒ Cache
Sets the cache to use.
95 96 97 |
# File 'lib/mongoid-cached-json/config.rb', line 95 def cache=(cache) settings[:cache] = cache end |
#default_cache ⇒ Cache
Returns the default cache store, for example Rails cache or an instance of ActiveSupport::Cache::MemoryStore.
74 75 76 |
# File 'lib/mongoid-cached-json/config.rb', line 74 def default_cache defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ::ActiveSupport::Cache::MemoryStore.new end |
#default_version ⇒ Version
Returns the default JSON version
53 54 55 56 |
# File 'lib/mongoid-cached-json/config.rb', line 53 def default_version settings[:default_version] = :unspecified unless settings.has_key?(:default_version) settings[:default_version] end |
#default_version=(default_version) ⇒ Version
Sets the default JSON version.
64 65 66 |
# File 'lib/mongoid-cached-json/config.rb', line 64 def default_version=(default_version) settings[:default_version] = default_version end |
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mongoid-cached-json/config.rb', line 26 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.
103 104 105 |
# File 'lib/mongoid-cached-json/config.rb', line 103 def reset! settings.replace(defaults) end |
#transform(&block) ⇒ Object
Define a transformation on JSON data.
113 114 115 116 117 |
# File 'lib/mongoid-cached-json/config.rb', line 113 def transform(& block) settings[:transform] = [] unless settings.has_key?(:transform) settings[:transform] << block if block_given? settings[:transform] end |