Sha256: ce8bb9a0fcea32f7bbd32f96c9aee0a805de97777f91e189e6b5db955579c39e
Contents?: true
Size: 1.4 KB
Versions: 6
Compression:
Stored size: 1.4 KB
Contents
# -*- encoding : utf-8 -*- 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
6 entries across 6 versions & 1 rubygems