Class: Thor::InstallTask

Inherits:
Task
  • Object
show all
Defined in:
lib/thor/tasks/install.rb

Instance Attribute Summary collapse

Attributes inherited from Task

#description, #name, #options, #usage

Instance Method Summary collapse

Methods inherited from Task

dynamic, #formatted_arguments, #formatted_options, #formatted_usage, #initialize_copy, #short_description

Constructor Details

#initialize(gemspec, config = {}) ⇒ InstallTask

Returns a new instance of InstallTask.



18
19
20
21
22
# File 'lib/thor/tasks/install.rb', line 18

def initialize(gemspec, config={})
  super(:install, "Install the gem", "install", {})
  @spec   = gemspec
  @config = { :dir => File.join(Dir.pwd, "pkg") }.merge(config)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



16
17
18
# File 'lib/thor/tasks/install.rb', line 16

def config
  @config
end

#specObject

Returns the value of attribute spec.



16
17
18
# File 'lib/thor/tasks/install.rb', line 16

def spec
  @spec
end

Instance Method Details

#run(instance, args = []) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/thor/tasks/install.rb', line 24

def run(instance, args=[])
  null, sudo, gem = RUBY_PLATFORM =~ /mswin|mingw/ ? ['NUL', '', 'gem.bat'] :
                                                     ['/dev/null', 'sudo', 'gem']

  old_stderr, $stderr = $stderr.dup, File.open(null, "w")
  instance.invoke(:package)
  $stderr = old_stderr

  system %{#{sudo} #{Gem.ruby} -S #{gem} install #{config[:dir]}/#{spec.name}-#{spec.version} --no-rdoc --no-ri --no-update-sources}
end