Class BoxGrinder::Config
In: lib/boxgrinder-core/models/config.rb
lib/boxgrinder-core/models/config.rb
Parent: OpenCascade

Methods

Public Class methods

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 25
25:     def initialize(values = {})
26:       super({})
27: 
28:       merge!(
29:           :file => ENV['BG_CONFIG_FILE'] || "#{ENV['HOME']}/.boxgrinder/config",
30:           :name => 'BoxGrinder Build',
31:           :platform => :none,
32:           :delivery => :none,
33:           :force => false,
34:           :log_level => :info,
35:           :backtrace => false,
36:           :dir => {
37:               :root => Dir.pwd,
38:               :build => 'build',
39:               :cache => '/var/cache/boxgrinder', # required for appliance-creator
40:               :tmp => '/tmp'
41:           },
42:           :os_config => {},
43:           :platform_config => {},
44:           :delivery_config => {},
45:           :additional_plugins => []
46:       )
47: 
48:       if ENV['BG_CONFIG_FILE']
49:         raise "You specified empty configuration file path. Please make sure you set correct path for BG_CONFIG_FILE environment variable." if ENV['BG_CONFIG_FILE'].strip.empty?
50:         raise "Configuration file '#{ENV['BG_CONFIG_FILE']}' couldn't be found. Please make sure you set correct path for BG_CONFIG_FILE environment variable." unless File.exists?(ENV['BG_CONFIG_FILE'])
51:       end
52: 
53:       deep_merge!(YAML.load_file(self.file)) if File.exists?(self.file)
54:       merge_with_symbols!(values)
55: 
56:       self.backtrace = true if [:debug, :trace].include?(self.log_level)
57:     end

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 25
25:     def initialize(values = {})
26:       super({})
27: 
28:       merge!(
29:           :file => ENV['BG_CONFIG_FILE'] || "#{ENV['HOME']}/.boxgrinder/config",
30:           :name => 'BoxGrinder Build',
31:           :platform => :none,
32:           :delivery => :none,
33:           :force => false,
34:           :log_level => :info,
35:           :backtrace => false,
36:           :dir => {
37:               :root => Dir.pwd,
38:               :build => 'build',
39:               :cache => '/var/cache/boxgrinder', # required for appliance-creator
40:               :tmp => '/tmp'
41:           },
42:           :os_config => {},
43:           :platform_config => {},
44:           :delivery_config => {},
45:           :additional_plugins => []
46:       )
47: 
48:       if ENV['BG_CONFIG_FILE']
49:         raise "You specified empty configuration file path. Please make sure you set correct path for BG_CONFIG_FILE environment variable." if ENV['BG_CONFIG_FILE'].strip.empty?
50:         raise "Configuration file '#{ENV['BG_CONFIG_FILE']}' couldn't be found. Please make sure you set correct path for BG_CONFIG_FILE environment variable." unless File.exists?(ENV['BG_CONFIG_FILE'])
51:       end
52: 
53:       deep_merge!(YAML.load_file(self.file)) if File.exists?(self.file)
54:       merge_with_symbols!(values)
55: 
56:       self.backtrace = true if [:debug, :trace].include?(self.log_level)
57:     end

Public Instance methods

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 67
67:     def deep_merge(first, second)
68:       second.each_key do |k|
69:         if first[k.to_sym].is_a?(Hash) and second[k].is_a?(Hash)
70:           deep_merge(first[k.to_sym], second[k])
71:         else
72:           first[k.to_sym] = second[k]
73:         end
74:       end if second
75:     end

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 67
67:     def deep_merge(first, second)
68:       second.each_key do |k|
69:         if first[k.to_sym].is_a?(Hash) and second[k].is_a?(Hash)
70:           deep_merge(first[k.to_sym], second[k])
71:         else
72:           first[k.to_sym] = second[k]
73:         end
74:       end if second
75:     end

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 63
63:     def deep_merge!(h)
64:       deep_merge(self, h)
65:     end

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 63
63:     def deep_merge!(h)
64:       deep_merge(self, h)
65:     end

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 59
59:     def merge_with_symbols!(values)
60:       merge!(values.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo })
61:     end

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 59
59:     def merge_with_symbols!(values)
60:       merge!(values.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo })
61:     end

[Validate]