Sha256: 51412faf376e32d07655620fe98fd1537ea5622197cb0d6d13620701e72d002b
Contents?: true
Size: 1.37 KB
Versions: 5
Compression:
Stored size: 1.37 KB
Contents
module Blacklight::Configurable # The config environment name used by the #config method # # Example: # class MyThing # extend Blacklight::Configurable # end # # Now MyThing.config will be the result of: # MyThing.configure(:production) {|config|} # # You set shared attributes by leaving the first argument blank or passing the :shared value: # MyThing.configure {|config|} # or # MyThing.cofigure(:shared) {|config|} # sets the @configs variable to a new Hash with empty Hash for :shared key and @config to nil def reset_configs! @config = nil @configs = {:shared=>{}} end # A hash of all environment configs # The key is the environment name, the value a Hash def configs @configs ? @configs : (reset_configs! and @configs) end # The main config accessor. It merges the current configs[::Rails.env] # with configs[:shared] and lazy-loads @config to the result. def config @config ||= configs[:shared].merge(configs[::Rails.env] ||= {}) end # Accepts a value for the environment to configure and a block # A hash is yielded to the block # If the "env" != :shared, # the hash is created by deep cloning the :shared environment config. # This makes it possible to create defaults in the :shared config def configure(env = :shared, &blk) configs[env] = {} yield configs[env] end end
Version data entries
5 entries across 5 versions & 1 rubygems