Geminstaller C0 Coverage Information - RCov

lib/geminstaller/rogue_gem_finder.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/geminstaller/rogue_gem_finder.rb 195 133
100.00%
100.00%

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 module GemInstaller
2   class RogueGemFinder
3     attr_writer :output_proxy, :gem_command_manager, :gem_spec_manager, :boilerplate_lines, :preinstalled_gem_names, :preinstalled_comment
4 
5     def print_rogue_gems(config_gems, config_file_paths)
6       @boilerplate_lines ||= default_boilerplate_lines(config_gems, config_file_paths)
7       @preinstalled_gem_names ||= default_preinstalled_gem_names
8       @preinstalled_comment ||= default_preinstalled_comment
9       @config_gems_with_dependencies = []
10       config_gems.each do |config_gem|
11         process_gem(config_gem)
12       end
13       all_local_gems = @gem_spec_manager.all_local_gems
14       rogue_gems = []
15       all_local_gems.each do |local_gem|
16         config_match_found_for_local = false
17         @config_gems_with_dependencies.each do |config_gem|
18           name_matches = config_gem.name == local_gem.name
19           config_gem_version_requirement = GemInstaller::REQUIREMENT_CLASS.new [config_gem.version]
20           local_gem_version = Gem::Version.new(local_gem.version)
21           version_matches = config_gem_version_requirement.satisfied_by?(local_gem_version)
22           if (name_matches and version_matches)
23             config_match_found_for_local = true
24             break
25           end
26         end
27         rogue_gems << local_gem unless config_match_found_for_local
28       end
29       yaml = format_to_yaml(rogue_gems)
30       
31       handle_output(yaml)
32     end
33     
34     def default_boilerplate_lines(config_gems, config_file_paths)
35       boilerplate = []
36       boilerplate <<  [
37         "#",
38         "# This is a GemInstaller config file (http://geminstaller.rubyforge.org)",
39         "# It was generated using the 'geminstaller --print-rogue-gems' option on #{Time.now}",
40         "#",
41         "# You can bootstrap your config by piping the output to a file: ",
42         "#   'geminstaller --print-rogue-gems > geminstaller.yml'",
43         "#",
44         "# You can then install these gems on another system by running geminstaller with this file.",
45         "#"
46       ]
47       
48       if config_file_paths.size == 0
49         boilerplate << "# Since there was no config file specified, the 'gems:' section below lists all gems on your system."
50       else
51         boilerplate << "# The following config file(s) and gems were already specified:"
52         boilerplate << "#   Files:"
53         config_file_paths.each do |config_file_path|
54           boilerplate << "#     * " + config_file_path
55         end
56         boilerplate << "#   Gems:"
57         if config_gems.size > 0
58           config_gems.each do |config_gem|
59             boilerplate << "#     * #{config_gem.name} #{config_gem.version}"
60           end
61         else
62           boilerplate << "#     No Gems"
63         end
64       end
65       boilerplate << "#"
66       boilerplate << "defaults:"
67       boilerplate << "  install_options: --include-dependencies"
68       return boilerplate
69     end
70     
71     def default_preinstalled_gem_names
72       # This is the list of preinstalled gems from the Ruby windows 1-click installer, v186-25
73       # 
74       # fxri (0.3.6)
75       #     Graphical interface to the RI documentation, with search engine.
76       # 
77       # fxruby (1.6.6)
78       #     FXRuby is the Ruby binding to the FOX GUI toolkit.
79       # 
80       # hpricot (0.4)
81       #     a swift, liberal HTML parser with a fantastic library
82       # 
83       # log4r (1.0.5)
84       #     Log4r is a comprehensive and flexible logging library for Ruby.
85       # 
86       # rake (0.7.2)
87       #     Ruby based make-like utility.
88       # 
89       # sources (0.0.1)
90       #     This package provides download sources for remote gem installation
91       # 
92       # win32-clipboard (0.4.1)
93       #     A package for interacting with the Windows clipboard
94       # 
95       # win32-dir (0.3.1)
96       #     Extra constants and methods for the Dir class on Windows.
97       # 
98       # win32-eventlog (0.4.3)
99       #     Interface for the MS Windows Event Log.
100       # 
101       # win32-file (0.5.3)
102       #     Extra or redefined methods for the File class on Windows.
103       # 
104       # win32-file-stat (1.2.3)
105       #     A File::Stat class tailored to MS Windows
106       # 
107       # win32-process (0.5.1)
108       #     Adds fork, wait, wait2, waitpid, waitpid2 and a special kill method
109       # 
110       # win32-sapi (0.1.3)
111       #     An interface to the MS SAPI (Sound API) library.
112       # 
113       # win32-sound (0.4.0)
114       #     A package for playing with sound on Windows.
115       # 
116       # windows-pr (0.6.2)
117       #     Windows functions and constants predefined via Win32API
118 
119       if RUBY_PLATFORM =~ /mswin/
120         return [
121           'fxri',
122           'fxruby',
123           'hpricot',
124           'log4r',
125           'rake',
126           'sources',
127           'win32-clipboard',
128           'win32-dir',
129           'win32-eventlog',
130           'win32-file',
131           'win32-file-stat',
132           'win32-process',
133           'win32-sapi',
134           'win32-sound',
135           'windows-pr'
136         ]
137       end
138       return ['sources']
139     end
140     
141     def default_preinstalled_comment
142       "# NOTE: This gem may have been automatially installed with Ruby, and not actually be used by your app(s)."
143     end
144     
145     def handle_output(yaml)
146       yaml_lines = yaml.split("\n")
147       yaml_doc_separator = yaml_lines.delete_at(0)
148       
149       output = []
150       output.push(yaml_doc_separator)
151       
152       output << @boilerplate_lines
153       
154       yaml_lines.each do |yaml_line| 
155         name_parser_regexp = /- name: (.*)/
156         yaml_line =~  name_parser_regexp
157         gem_name = $1
158         preinstalled_comment = ''
159         if @preinstalled_gem_names.include?(gem_name)
160           preinstalled_comment = " " + @preinstalled_comment
161         end
162         output.push yaml_line + preinstalled_comment
163       end
164       
165       output_string = output.join("\n")
166       @output_proxy.sysout output_string
167       output_string
168     end
169     
170     def process_gem(gem)
171       @config_gems_with_dependencies << gem
172       process_gem_dependencies(gem)
173     end
174 
175     def process_gem_dependencies(gem)
176       # TODO: this method is duplicated in autogem  Should abstract and take a block
177       matching_gems = @gem_spec_manager.local_matching_gems(gem)
178       matching_gems.each do |matching_gem|
179         dependency_gems = @gem_command_manager.dependency(matching_gem.name, matching_gem.version.to_s)
180         dependency_gems.each do |dependency_gem|
181           process_gem(dependency_gem)
182         end
183       end
184     end
185 
186     def format_to_yaml(gems)
187       names_and_versions = []
188       gems.each do |gem|
189         names_and_versions << {'name' => gem.name, 'version' => gem.version}
190       end
191       hash_for_yaml = {'gems' => names_and_versions}
192       YAML.dump(hash_for_yaml)
193     end
194   end
195 end

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