Class: TomatoHarvest::Config

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

Constant Summary collapse

DIR_NAME =
'.toma'
HOME_DIR =
ENV['HOME']
GLOBAL_DIR =
File.join(HOME_DIR, DIR_NAME)
LOCAL_DIR =
File.join(Dir.pwd, DIR_NAME)

Class Method Summary collapse

Class Method Details

.config_path(directory) ⇒ Object



30
31
32
# File 'lib/tomatoharvest/config.rb', line 30

def self.config_path(directory)
  File.join(directory, 'config.yaml')
end

.loadObject



9
10
11
12
13
14
15
16
17
# File 'lib/tomatoharvest/config.rb', line 9

def self.load
  old_config    = merge_config(old_config_path)

  global_path = config_path(GLOBAL_DIR)
  global_config = merge_config(global_path, old_config)

  local_path = config_path(LOCAL_DIR)
  merge_config(local_path, global_config)
end

.merge_config(path, base = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/tomatoharvest/config.rb', line 19

def self.merge_config(path, base = {})
  mergable =
    if File.exists?(path) 
      YAML.load_file(path)
    else
      {}
    end

  base.merge(mergable)
end

.old_config_pathObject



34
35
36
# File 'lib/tomatoharvest/config.rb', line 34

def self.old_config_path
  File.join(HOME_DIR, '.tomaconfig')
end