Skip to content

Commit

Permalink
When configloader is used in a Rails App, it's better to rely on Rail…
Browse files Browse the repository at this point in the history
…s.env instead of ENV['RAILS_ENV'] or ENV['RACK_ENV']. Also, it's betther to rely on Rails.root, instead of ENV['RAILS_ROOT'] or ENV['RACK_ROOT']. So I changed the loader in order to firstly use Rails.env and Rails.root, but fallback to the environment variables if necessary.
  • Loading branch information
viniciusteles committed Feb 9, 2011
1 parent 8128335 commit 3f380ae
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/config_loader.rb
Expand Up @@ -47,7 +47,19 @@ module ConfigLoader
# server: <%= `hostname` %>
# port: 5984
# database_name: addressbook_test
def self.load(file_name, running_env = ENV['RAILS_ENV'], project_root = ENV['RAILS_ROOT'])
def self.load(file_name, running_env = default_running_env, project_root = default_project_root)
ConfigLoader::Map.new(file_name, running_env, project_root).load
end

private

def self.default_running_env
return Rails.env if defined?(Rails)
ENV['RAILS_ENV'] || ENV['RACK_ENV']
end

def self.default_project_root
return Rails.root if defined?(Rails)
ENV['RAILS_ROOT'] || ENV['RACK_ROOT']
end
end

0 comments on commit 3f380ae

Please sign in to comment.