module Magiconf
Constants
- VERSION
Public Instance Methods
setup!()
click to toggle source
For each configuration key, define a method inside the module
# File lib/magiconf.rb, line 5 def setup! configuration = config configuration.keys.each do |key| nodule.define_singleton_method key do return configuration[key] end end nodule.define_singleton_method :method_missing do |m, *args, &block| nil end end
setup?()
click to toggle source
Have we already loaded the magiconf config? @return [Boolean] true if we have been loaded, false otherwise
# File lib/magiconf.rb, line 21 def setup? namespace.constants.include?('Config') # Note: We cannot use const_defined?('Config') # here because that will recursively search up # Object and find RbConfig end
Private Instance Methods
config()
click to toggle source
The configuration yaml file @return [Hash] the parsed yaml data
# File lib/magiconf.rb, line 42 def config @config ||= begin config = YAML::load( ERB.new( File.read('config/application.yml') ).result ) config.merge!( config.fetch(Rails.env, {}) ) config.symbolize_keys! config end end
namespace()
click to toggle source
Get the namespace for the current application @return [Module] the namespace of the Rails app
# File lib/magiconf.rb, line 30 def namespace @namespace ||= Rails.application.class.parent_name.constantize end
nodule()
click to toggle source
Create a new Config module in the current namespace @return [Module] the created module
# File lib/magiconf.rb, line 36 def nodule @nodule ||= namespace.const_set('Config', Module.new) end