Sha256: f2d9f4757124005fdef44403516e1febf4de45b60c470b9cdb08291154c95559
Contents?: true
Size: 1.72 KB
Versions: 11
Compression:
Stored size: 1.72 KB
Contents
require 'pp' module Chargify module Config class << self # the configuration hash itself def configuration @configuration ||= defaults end def defaults { :logger => defined?(Rails.logger) ? Rails.logger : Logger.new(STDOUT), :debug => false, :subdomain => "your-site-name", :api_key => "your-api-key" } end def [](key) configuration[key] end def []=(key, val) configuration[key] = val end # remove an item from the configuration def delete(key) configuration.delete(key) end # Return the value of the key, or the default if doesn't exist # # ==== Examples # # Chargify::Config.fetch(:monkey, false) # => false # def fetch(key, default) configuration.fetch(key, default) end def to_hash configuration end # Yields the configuration. # # ==== Examples # Chargify::Config.use do |config| # config[:debug] = true # config.something = false # end # def setup yield self nil end def clear @configuration = {} end def reset @configuration = defaults end # allow getting and setting properties via Chargify::Config.xxx # # ==== Examples # Chargify::Config.debug # Chargify::Config.debug = false # def method_missing(method, *args) if method.to_s[-1,1] == '=' configuration.send(:[]=, method.to_s.tr('=','').to_sym, *args) else configuration[method] end end end end end
Version data entries
11 entries across 11 versions & 2 rubygems