Check if Rails module responds to env and root before using them

This commit is contained in:
Andrei Bocan 2011-03-28 09:51:27 -04:00 committed by Chris Eppstein
parent 1bd156e88f
commit c4a315af3c

View File

@ -21,13 +21,19 @@ module Compass
end end
def env def env
if rails_env = (defined?(::Rails) ? ::Rails.env : (defined?(RAILS_ENV) ? RAILS_ENV : nil)) env_production? ? :production : :development
rails_env.production? ? :production : :development end
def env_production?
if defined?(::Rails) && ::Rails.respond_to?(:env)
::Rails.env.production?
elsif defined?(RAILS_ENV)
RAILS_ENV == "production"
end end
end end
def root def root
if defined?(::Rails) if defined?(::Rails) && ::Rails.respond_to?(:root)
::Rails.root ::Rails.root
elsif defined?(RAILS_ROOT) elsif defined?(RAILS_ROOT)
RAILS_ROOT RAILS_ROOT