Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't evalutate strings for built-in tasks.

Also add an argument for passing the gemspec to package_task and install_task,
rather than relying on certain constants being defined.
  • Loading branch information...
commit 2e9cfcae1db6aa16b1331cf02f55cdf3bbf78a86 1 parent 896f369
@nex3 nex3 authored
Showing with 31 additions and 37 deletions.
  1. +1 −1  Thorfile
  2. +30 −36 lib/thor/tasks.rb
View
2  Thorfile
@@ -34,7 +34,7 @@ class Default < Thor
spec_task(Dir["spec/**/*_spec.rb"])
spec_task(Dir["spec/**/*_spec.rb"], :name => "rcov", :rcov =>
{:exclude => %w(spec /Library /Users task.thor lib/getopt.rb)})
- install_task
+ install_task SPEC
desc "make_spec", "make a gemspec file"
def make_spec
View
66 lib/thor/tasks.rb
@@ -2,29 +2,25 @@
require "fileutils"
class Thor
- def self.package_task
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
- desc "package", "package up the gem"
- def package
- FileUtils.mkdir_p(File.join(Dir.pwd, "pkg"))
- Gem::Builder.new(SPEC).build
- FileUtils.mv(SPEC.file_name, File.join(Dir.pwd, "pkg", SPEC.file_name))
- end
- RUBY
+ def self.package_task(spec)
+ desc "package", "package up the gem"
+ define_method :package do
+ FileUtils.mkdir_p(File.join(Dir.pwd, "pkg"))
+ Gem::Builder.new(spec).build
+ FileUtils.mv(spec.file_name, File.join(Dir.pwd, "pkg", spec.file_name))
+ end
end
- def self.install_task
- package_task
+ def self.install_task(spec)
+ package_task spec
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
- desc "install", "install the gem"
- def install
- old_stderr, $stderr = $stderr.dup, File.open("/dev/null", "w")
- package
- $stderr = old_stderr
- system %{sudo gem install pkg/#{GEM}-#{GEM_VERSION} --no-rdoc --no-ri --no-update-sources}
- end
- RUBY
+ desc "install", "install the gem"
+ define_method :install do
+ old_stderr, $stderr = $stderr.dup, File.open("/dev/null", "w")
+ package
+ $stderr = old_stderr
+ system %{sudo gem install pkg/#{spec.name}-#{spec.version} --no-rdoc --no-ri --no-update-sources}
+ end
end
def self.spec_task(file_list, opts = {})
@@ -42,23 +38,21 @@ def self.spec_task(file_list, opts = {})
FileUtils.rm_rf(File.join(Dir.pwd, rcov_dir))
end
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
- desc("#{name}", "spec task")
- def #{name}
- cmd = "ruby "
- if #{rcov.inspect}
- cmd << "-S rcov -o #{rcov_dir} #{rcov_opts.inspect[1...-1]} "
- end
- cmd << `which spec`.chomp
- cmd << " -- " if #{rcov.inspect}
- cmd << " "
- cmd << #{file_list.inspect}
- cmd << " "
- cmd << #{options.inspect}
- puts cmd if #{verbose.inspect}
- system(cmd)
+ desc(name, "spec task")
+ define_method(name) do
+ cmd = "ruby "
+ if rcov
+ cmd << "-S rcov -o #{rcov_dir} #{rcov_opts} "
end
- RUBY
+ cmd << `which spec`.chomp
+ cmd << " -- " if rcov
+ cmd << " "
+ cmd << file_list
+ cmd << " "
+ cmd << options
+ puts cmd if verbose
+ system(cmd)
+ end
end
private

0 comments on commit 2e9cfca

Please sign in to comment.
Something went wrong with that request. Please try again.