module Rlt::Config

Public Instance Methods

config(category, command) click to toggle source
# 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) click to toggle source
# File lib/rlt/config.rb, line 18
def config_keys(category)
  c = config_map.dig(category)
  return [] if c.nil?
  c.keys
end
config_map() click to toggle source
# File lib/rlt/config.rb, line 46
def config_map
  (@config_map ||= load_all_configs)
end
global_config_path() click to toggle source
# File lib/rlt/config.rb, line 38
def global_config_path
  File.expand_path('~/.rlt.yml')
end
load_all_configs() click to toggle source
# 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) click to toggle source
# 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_path() click to toggle source
# 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) click to toggle source
# File lib/rlt/config.rb, line 14
def original_name_of_alias(command)
  config_map.dig 'alias', command
end