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

Methods

Public Class methods

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 26
26:     def initialize(values = {})
27:       super({})
28: 
29:       merge!(
30:           :file => ENV['BG_CONFIG_FILE'] || "#{ENV['HOME']}/.boxgrinder/config",
31:           :name => 'BoxGrinder Build',
32:           :platform => :none,
33:           :delivery => :none,
34:           :force => false,
35:           :log_level => :info,
36:           :backtrace => false,
37:           :dir => {
38:               :root => Dir.pwd,
39:               :build => 'build',
40:               :cache => '/var/cache/boxgrinder', # required for appliance-creator
41:               :tmp => '/tmp'
42:           },
43:           :os_config => {},
44:           :platform_config => {},
45:           :delivery_config => {},
46:           :additional_plugins => []
47:       )
48: 
49:       if ENV['BG_CONFIG_FILE']
50:         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?
51:         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'])
52:       end
53: 
54:       deep_merge!(YAML.load_file(self.file)) if File.exists?(self.file)
55:       merge_with_symbols!(values)
56: 
57:       self.backtrace = true if [:debug, :trace].include?(self.log_level)
58: 
59:       populate_user_ids!
60:     end

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 26
26:     def initialize(values = {})
27:       super({})
28: 
29:       merge!(
30:           :file => ENV['BG_CONFIG_FILE'] || "#{ENV['HOME']}/.boxgrinder/config",
31:           :name => 'BoxGrinder Build',
32:           :platform => :none,
33:           :delivery => :none,
34:           :force => false,
35:           :log_level => :info,
36:           :backtrace => false,
37:           :dir => {
38:               :root => Dir.pwd,
39:               :build => 'build',
40:               :cache => '/var/cache/boxgrinder', # required for appliance-creator
41:               :tmp => '/tmp'
42:           },
43:           :os_config => {},
44:           :platform_config => {},
45:           :delivery_config => {},
46:           :additional_plugins => []
47:       )
48: 
49:       if ENV['BG_CONFIG_FILE']
50:         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?
51:         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'])
52:       end
53: 
54:       deep_merge!(YAML.load_file(self.file)) if File.exists?(self.file)
55:       merge_with_symbols!(values)
56: 
57:       self.backtrace = true if [:debug, :trace].include?(self.log_level)
58: 
59:       populate_user_ids!
60:     end

Public Instance methods

[Source]

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

[Source]

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

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 66
66:     def deep_merge!(h)
67:       deep_merge(self, h)
68:     end

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 66
66:     def deep_merge!(h)
67:       deep_merge(self, h)
68:     end

[Source]

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

[Source]

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

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 80
80:     def populate_user_ids!
81:       self.uid = Process.uid
82:       self.gid = Process.gid
83:       begin
84:         if env = ENV['SUDO_USER'] || ENV['LOGNAME']
85:           user = Etc.getpwnam(env)
86:           self.uid = user.uid
87:           self.gid = user.gid
88:         end
89:       rescue ArgumentError #No such name, just use initial defaults.
90:       end
91:     end

[Source]

    # File lib/boxgrinder-core/models/config.rb, line 80
80:     def populate_user_ids!
81:       self.uid = Process.uid
82:       self.gid = Process.gid
83:       begin
84:         if env = ENV['SUDO_USER'] || ENV['LOGNAME']
85:           user = Etc.getpwnam(env)
86:           self.uid = user.uid
87:           self.gid = user.gid
88:         end
89:       rescue ArgumentError #No such name, just use initial defaults.
90:       end
91:     end

[Validate]