diff --git a/lib/railsless_rake_task_runner.rb b/lib/railsless_rake_task_runner.rb index a1f17a7..94aae13 100644 --- a/lib/railsless_rake_task_runner.rb +++ b/lib/railsless_rake_task_runner.rb @@ -10,35 +10,37 @@ def self.load_rails end end -# Try to run no-rails tasks first. Fallback to rails if none is found. -Rake.application.instance_eval do - module Rake - class Task - alias :old_lookup_prerequisite :lookup_prerequisite +if defined?(Rake) + # Try to run no-rails tasks first. Fallback to rails if none is found. + Rake.application.instance_eval do + module Rake + class Task + alias :old_lookup_prerequisite :lookup_prerequisite - def lookup_prerequisite(prerequisite_name) - if prerequisite_name == "environment" && !Rake.application.lookup(prerequisite_name) - RailslessRakeTaskRunner.load_rails + def lookup_prerequisite(prerequisite_name) + if prerequisite_name == "environment" && !Rake.application.lookup(prerequisite_name) + RailslessRakeTaskRunner.load_rails + end + old_lookup_prerequisite(prerequisite_name) end - old_lookup_prerequisite(prerequisite_name) end end - end - def top_level - if running_a_task? && requested_tasks_exist? - super - else - RailslessRakeTaskRunner.load_rails - super + def top_level + if running_a_task? && requested_tasks_exist? + super + else + RailslessRakeTaskRunner.load_rails + super + end end - end - def running_a_task? - !(options.show_tasks || options.show_prereqs) - end + def running_a_task? + !(options.show_tasks || options.show_prereqs) + end - def requested_tasks_exist? - top_level_tasks.any? { |task| lookup(task) } + def requested_tasks_exist? + top_level_tasks.any? { |task| lookup(task) } + end end end