Parent

GemInstaller::ConfigBuilder

Attributes

config_file_paths_array[R]
file_reader[W]
yaml_loader[W]
config_file_paths[W]
output_filter[W]

Public Class Methods

new(default_config_file_paths_array = ['geminstaller.yml','config/geminstaller.yml','ci/geminstaller.yml']) click to toggle source
    # File lib/geminstaller/config_builder.rb, line 9
 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

Public Instance Methods

build_config() click to toggle source
    # File lib/geminstaller/config_builder.rb, line 13
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
include_config(config_file) click to toggle source
    # File lib/geminstaller/config_builder.rb, line 56
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
include_config_binding() click to toggle source
    # File lib/geminstaller/config_builder.rb, line 55
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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.