Class: MrBump::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/mr_bump/config.rb

Overview

This class sets up access to the config file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file = nil) ⇒ Config

Returns a new instance of Config.



12
13
14
# File 'lib/mr_bump/config.rb', line 12

def initialize(config_file = nil)
  @config_file = config_file || default_project_filename
end

Instance Attribute Details

#config_fileObject (readonly)

Returns the value of attribute config_file.



10
11
12
# File 'lib/mr_bump/config.rb', line 10

def config_file
  @config_file
end

Instance Method Details

#configObject



45
46
47
# File 'lib/mr_bump/config.rb', line 45

def config
  @config ||= default_config.merge(user_config).merge(project_config)
end

#default_configObject



24
25
26
27
28
29
# File 'lib/mr_bump/config.rb', line 24

def default_config
  @default_config = begin
    defaults_yml = File.join(File.dirname(__FILE__), '..', '..', 'defaults.yml')
    YAML.load_file(defaults_yml)
  end
end

#default_project_filenameObject



20
21
22
# File 'lib/mr_bump/config.rb', line 20

def default_project_filename
  File.join('.mr_bump')
end

#project_configObject



38
39
40
41
42
43
# File 'lib/mr_bump/config.rb', line 38

def project_config
  @project_config ||= begin
    loaded = YAML.load_file(@config_file) if File.exist?(@config_file)
    loaded || {}
  end
end

#user_configObject



31
32
33
34
35
36
# File 'lib/mr_bump/config.rb', line 31

def user_config
  @user_config = begin
    loaded = YAML.load_file(user_config_file) if File.exist?(user_config_file)
    loaded || {}
  end
end

#user_config_fileObject



16
17
18
# File 'lib/mr_bump/config.rb', line 16

def user_config_file
  File.join(Dir.home, '.mr_bump.yml')
end