You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rubygem-thor/thor-rake-0.9-compat.patch

116 lines
2.9 KiB

commit 11c8748933cc611972f32831657ab99e6701bd93
Author: Yehuda Katz <wycats@gmail.com>
Date: Sat Jul 2 20:50:39 2011 -0700
Upgrade Rake compatibility for the more constrained Rake 0.9
diff --git a/lib/thor/rake_compat.rb b/lib/thor/rake_compat.rb
index 0d0757f..b3a8beb 100644
--- a/lib/thor/rake_compat.rb
+++ b/lib/thor/rake_compat.rb
@@ -1,4 +1,5 @@
require 'rake'
+require 'rake/dsl_definition'
class Thor
# Adds a compatibility layer to your Thor classes which allows you to use
@@ -16,6 +17,8 @@ class Thor
# end
#
module RakeCompat
+ include Rake::DSL if defined?(Rake::DSL)
+
def self.rake_classes
@rake_classes ||= []
end
@@ -29,12 +32,12 @@ class Thor
end
end
-class Object #:nodoc:
- alias :rake_task :task
- alias :rake_namespace :namespace
+# override task on (main), for compatibility with Rake 0.9
+self.instance_eval do
+ alias rake_namespace namespace
- def task(*args, &block)
- task = rake_task(*args, &block)
+ def task(*)
+ task = super
if klass = Thor::RakeCompat.rake_classes.last
non_namespaced_name = task.name.split(':').last
@@ -52,7 +55,7 @@ class Object #:nodoc:
task
end
- def namespace(name, &block)
+ def namespace(name)
if klass = Thor::RakeCompat.rake_classes.last
const_name = Thor::Util.camel_case(name.to_s).to_sym
klass.const_set(const_name, Class.new(Thor))
@@ -60,7 +63,8 @@ class Object #:nodoc:
Thor::RakeCompat.rake_classes << new_klass
end
- rake_namespace(name, &block)
+ super
Thor::RakeCompat.rake_classes.pop
end
end
+
diff --git a/lib/thor/task.rb b/lib/thor/task.rb
index 6db3b60..8dcff53 100644
--- a/lib/thor/task.rb
+++ b/lib/thor/task.rb
@@ -104,7 +104,11 @@ class Thor
def run(instance, args=[])
if (instance.methods & [name.to_s, name.to_sym]).empty?
- super
+ if ((instance.protected_methods + instance.public_methods) & ([:method_missing, "method_missing"])).empty?
+ super
+ else
+ instance.send(:method_missing, name.to_sym, *args)
+ end
else
instance.class.handle_no_task_error(name)
end
diff --git a/spec/rake_compat_spec.rb b/spec/rake_compat_spec.rb
index f8d694c..0b642aa 100644
--- a/spec/rake_compat_spec.rb
+++ b/spec/rake_compat_spec.rb
@@ -2,20 +2,24 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'thor/rake_compat'
require 'rake/tasklib'
+$main = self
+
class RakeTask < Rake::TaskLib
def initialize
define
end
def define
- desc "Say it's cool"
- task :cool do
- puts "COOL"
- end
+ $main.instance_eval do
+ desc "Say it's cool"
+ task :cool do
+ puts "COOL"
+ end
- namespace :hiper_mega do
- task :super do
- puts "HIPER MEGA SUPER"
+ namespace :hiper_mega do
+ task :super do
+ puts "HIPER MEGA SUPER"
+ end
end
end
end