Geminstaller C0 Coverage Information - RCov

lib/geminstaller.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/geminstaller.rb 103 84
56.31%
52.38%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 dir = File.dirname(__FILE__)
2 require File.expand_path("#{dir}/geminstaller/requires.rb")
3 
4 module GemInstaller
5   def self.install(args = [], geminstaller_executable = nil)
6     args_copy = args.dup
7     args_copy = args_copy.split(' ') unless args.respond_to? :join
8     # recursively call script with sudo, if --sudo option is specified
9     if platform_supports_sudo? and (args_copy.include?("-s") or args_copy.include?("--sudo"))
10       result = reinvoke_with_sudo(args_copy, geminstaller_executable)
11       if result != 0 and (args_copy.include?("-e") or args_copy.include?("--exceptions"))
12         message = "Error: GemInstaller failed while being invoked with --sudo option.  See prior output for error, and use '--geminstaller-output=all --rubygems-output=all' options to get more details."
13         raise GemInstaller::GemInstallerError.new(message)
14       end
15       return result
16     else
17       app = create_application(args_copy)
18       app.install
19     end
20   end
21   
22   def self.run(args = [], geminstaller_executable = nil)
23     # run is now an alias for install
24     install(args, geminstaller_executable)
25   end
26   
27   def self.autogem(args = [])
28     args_copy = args.dup
29     args_copy = args_copy.split(' ') unless args.respond_to? :join
30     # TODO: should explicitly remove all args not applicable to autogem (anything but config, silent, and geminstaller_output)
31     args_without_sudo = strip_sudo(args_copy)
32     app = create_application(args_without_sudo)
33     app.autogem
34   end
35 
36   def self.version
37     "0.5.6"
38   end
39 
40   def self.create_application(args = [], registry = nil)
41     registry ||= create_registry
42     app = registry.app
43     app.args = args
44     app
45   end
46   
47   def self.create_registry
48     GemInstaller::Registry.new
49   end
50   
51   def self.parse_config_paths(config_paths)
52     return nil unless config_paths
53     return config_paths unless config_paths.respond_to? :join
54     return config_paths.join(',')
55   end
56   
57   def self.platform_supports_sudo?
58     return true unless RUBY_PLATFORM =~ /mswin/
59     return false
60   end
61   
62   def self.reinvoke_with_sudo(args, geminstaller_executable)
63     # Sudo support is a hack, better to use other alternatives.
64     geminstaller_executable ||= find_geminstaller_executable
65     args_without_sudo = strip_sudo(args)
66     args_without_sudo << '--redirect-stderr-to-stdout'
67     cmd = "sudo ruby #{geminstaller_executable} #{args_without_sudo.join(' ')}"
68     # TODO: this eats any output.  There currently is no standard way to get a return code AND stdin AND stdout.
69     # Some non-standard packages like Open4 handle this, but not synchronously.  The Simplest Thing That Could
70     # Possibly Work is to have a command line option which will cause all stderr output to be redirected to stdout.
71     result = system(cmd)
72     return 1 unless result
73     return $?.exitstatus
74   end
75   
76   def self.strip_sudo(args)
77     return args.reject {|arg| arg == "-s" || arg == "--sudo"}
78   end
79   
80   def self.find_geminstaller_executable
81     possible_locations = [
82       'ruby -S geminstaller',
83       'ruby /usr/local/bin/geminstaller',
84       'ruby /usr/bin/geminstaller',
85       'ruby ./bin/geminstaller'
86       ]
87     path_key = 'geminstaller_exec_path='
88     possible_locations.each do |possible_location|
89       cmd = "#{possible_location} --geminstaller-exec-path"
90 
91       $stderr_backup = $stderr.dup
92       $stderr.reopen("/dev/null", "w")
93       io = IO.popen(cmd)
94       $stderr.reopen($stderr_backup)
95       STDERR.reopen($stderr_backup) # Why are these not the same?  It is an old question: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/47596
96       output = io.read
97       next unless output =~ /#{path_key}/
98       path = output.sub(path_key,'')
99       return path
100     end
101     raise GemInstaller::GemInstallerError.new("Error: Unable to locate the geminstaller executable.  Specify it explicitly, or don't use the sudo option.")
102   end
103 end

Generated on Mon May 10 23:40:28 -0700 2010 with rcov 0.9.8