lib/configoro/base.rb in configoro-1.2.3 vs lib/configoro/base.rb in configoro-1.2.4

- old
+ new

@@ -1,19 +1,12 @@ # This module handles initialization of the Configoro object, and contains some # utility methods. module Configoro - # @return [Module] The Rails application namespace; e.g., @MyApp@ for a Rails - # app named @MyApp::Application@. - - def self.namespace - Object.const_get Rails.application.class.to_s.split('::').first - end - # Creates the configuration dictionary and stores it under - # @MyApp::Configuration@ (assuming an application named @MyApp@). + # `MyApp::Configuration` (assuming an application named `MyApp`). def self.initialize namespace.const_set :Configuration, load_environment(Rails.env) end @@ -40,10 +33,16 @@ paths << "#{Rails.root}/config/environments" if defined?(Rails) paths end end + # Resets any custom configuration paths set using {.paths}. + + def self.reset_paths + remove_instance_variable :@paths + end + # Loads the configuration for an environment and returns it as a {Hash}. Use # this method to access Configoro options outside the context of your Rails # app. You will need to configure paths first (see example). # # @param [String] env The Rails environment. @@ -52,15 +51,19 @@ # @example Accessing Configoro options outside of Rails # Configoro.paths << "#{rails_root}/config/environments" # Configoro.load_environment(rails_env) #=> { ... } def self.load_environment(env) - config = Hash.new + config = Configoro::Hash.new load_data config, env config end private + + def self.namespace + Object.const_get Rails.application.class.to_s.split('::').first + end def self.load_data(config, env) paths.each do |path| Dir.glob("#{path}/common/*.yml").sort.each { |file| config << file } Dir.glob("#{path}/#{env}/*.yml").sort.each { |file| config << file }