Class: MrBump::Config
- Inherits:
-
Object
- Object
- MrBump::Config
- Defined in:
- lib/mr_bump/config.rb
Overview
This class sets up access to the config file
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
Instance Method Summary collapse
- #config ⇒ Object
- #default_config ⇒ Object
- #default_project_filename ⇒ Object
-
#initialize(config_file = nil) ⇒ Config
constructor
A new instance of Config.
- #project_config ⇒ Object
- #user_config ⇒ Object
- #user_config_file ⇒ Object
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_file ⇒ Object (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
#config ⇒ Object
45 46 47 |
# File 'lib/mr_bump/config.rb', line 45 def config @config ||= default_config.merge(user_config).merge(project_config) end |
#default_config ⇒ Object
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_filename ⇒ Object
20 21 22 |
# File 'lib/mr_bump/config.rb', line 20 def default_project_filename File.join('.mr_bump') end |
#project_config ⇒ Object
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_config ⇒ Object
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_file ⇒ Object
16 17 18 |
# File 'lib/mr_bump/config.rb', line 16 def user_config_file File.join(Dir.home, '.mr_bump.yml') end |