Geminstaller C0 Coverage Information - RCov

lib/geminstaller/config_builder.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/geminstaller/config_builder.rb 65 61
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 dir = File.dirname(__FILE__)
2 require File.expand_path("#{dir}/requires.rb")
3 
4 module GemInstaller
5   class ConfigBuilder
6     attr_reader :config_file_paths_array
7     attr_writer :file_reader, :yaml_loader, :config_file_paths, :output_filter
8     
9     def initialize(default_config_file_paths_array = ['geminstaller.yml','config/geminstaller.yml','ci/geminstaller.yml'])
10       @default_config_file_paths_array = default_config_file_paths_array
11     end
12     
13     def build_config
14       @config_file_paths_array = @config_file_paths ? @config_file_paths.split(",") : @default_config_file_paths_array
15       merged_defaults = {}
16       merged_gems_in_order = []
17       merged_gems_by_key = {}
18       file_found = false
19       @config_file_paths_array.reverse.each do |path| # reverse because last config files win
20         if File.exists?(path)
21           file_found = true
22         else
23           next
24         end
25         file_contents = @file_reader.read(path)
26         next unless file_contents
27         next if file_contents.empty?
28         expanded_path = File.expand_path(path)
29         @output_filter.geminstaller_output(:debug,"Found GemInstaller config file at: #{expanded_path}\n")
30         erb = ERB.new(%{#{file_contents}})
31         erb_result = nil
32         Dir.chdir(File.dirname(expanded_path)) do |yaml_file_dir|
33           erb_result = erb.result(include_config_binding)
34         end
35         yaml = @yaml_loader.load(erb_result)
36         merged_defaults.merge!(yaml['defaults']) unless yaml['defaults'].nil?
37         next unless yaml['gems']
38         yaml['gems'].each do |new_gem|
39           gem_key = [new_gem['name'],new_gem['version'],new_gem['platform']].join('-')
40           existing_gem = merged_gems_by_key[gem_key]
41           unless existing_gem
42             merged_gems_in_order << new_gem
43             merged_gems_by_key[gem_key] = new_gem
44           end
45         end
46       end
47       raise GemInstaller::MissingFileError.new("No config files found at any of these paths: #{@config_file_paths_array.join(', ')}") unless file_found
48       merged_yaml = {}
49       merged_yaml['defaults'] = merged_defaults
50       merged_yaml['gems'] = merged_gems_in_order
51       config = GemInstaller::Config.new(merged_yaml)
52       config
53     end
54   
55     def include_config_binding
56       def include_config(config_file)
57         Dir.chdir(File.dirname(config_file)) do |yaml_file_dir|
58           erb = File.open(config_file) { |io| ERB.new(io.read) }
59           erb.result(include_config_binding)
60         end
61       end
62       binding
63     end
64   end
65 end

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