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
def env
if rails_env = (defined?(::Rails) ? ::Rails.env : (defined?(RAILS_ENV) ? RAILS_ENV : nil))
rails_env.production? ? :production : :development
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
def root
if defined?(::Rails)
if defined?(::Rails) && ::Rails.respond_to?(:root)
::Rails.root
elsif defined?(RAILS_ROOT)
RAILS_ROOT