Module: Rlt::Config

Included in:
Rlt
Defined in:
lib/rlt/config.rb

Instance Method Summary collapse

Instance Method Details

#config(category, command) ⇒ Object



7
8
9
10
11
12
# File 'lib/rlt/config.rb', line 7

def config(category, command)
  c = config_map.dig category, command
  return c unless c.nil?
  return {} if command == original_name_of_alias(command)
  config_map.dig(category, original_name_of_alias(command)) || {}
end

#config_keys(category) ⇒ Object



18
19
20
21
22
# File 'lib/rlt/config.rb', line 18

def config_keys(category)
  c = config_map.dig(category)
  return [] if c.nil?
  c.keys
end

#config_mapObject



46
47
48
# File 'lib/rlt/config.rb', line 46

def config_map
  (@config_map ||= load_all_configs)
end

#global_config_pathObject



38
39
40
# File 'lib/rlt/config.rb', line 38

def global_config_path
  File.expand_path('~/.rlt.yml')
end

#load_all_configsObject



42
43
44
# File 'lib/rlt/config.rb', line 42

def load_all_configs
  load_config(global_config_path).merge(load_config(local_config_path))
end

#load_config(path) ⇒ Object



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

def load_config(path)
  result = YAML.load_file(path)
  return result if result.is_a? Hash
  {}
rescue Errno::ENOENT
  {}
end

#local_config_pathObject



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

def local_config_path
  sample_config_path = "#{Dir.pwd}/.rlt.sample.yml"
  return sample_config_path if Rlt.debug && File.exist?(sample_config_path)
  "#{Dir.pwd}/.rlt.yml"
end

#original_name_of_alias(command) ⇒ Object



14
15
16
# File 'lib/rlt/config.rb', line 14

def original_name_of_alias(command)
  config_map.dig 'alias', command
end