class Tagrity::ConfigFile

Constants

CONFIG_FNAME

Public Instance Methods

command_for_extension(extension) click to toggle source
# File lib/tagrity/config_file.rb, line 29
def command_for_extension(extension)
  cmd = extension_commands[extension.to_s]
  if cmd.nil?
    default_command
  else
    cmd
  end
end
default_command() click to toggle source
# File lib/tagrity/config_file.rb, line 58
def default_command
  @config['default_command']
end
excluded_paths() click to toggle source
# File lib/tagrity/config_file.rb, line 78
def excluded_paths
  @config['excluded_paths']
end
extension_commands() click to toggle source
# File lib/tagrity/config_file.rb, line 54
def extension_commands
  @config['extension_commands']
end
extensions_blacklist() click to toggle source
# File lib/tagrity/config_file.rb, line 70
def extensions_blacklist
  @config['extensions_blacklist']
end
extensions_whitelist() click to toggle source
# File lib/tagrity/config_file.rb, line 66
def extensions_whitelist
  @config['extensions_whitelist']
end
git_strategy() click to toggle source
# File lib/tagrity/config_file.rb, line 74
def git_strategy
  @config['git_strategy']
end
ignore_extension?(extension) click to toggle source
# File lib/tagrity/config_file.rb, line 38
def ignore_extension?(extension)
  unless extensions_whitelist.empty?
    return !extensions_whitelist.include?(extension.to_s)
  end

  extensions_blacklist.include?(extension.to_s)
end
initial_load() click to toggle source
# File lib/tagrity/config_file.rb, line 23
def initial_load
  if @config.nil?
    read_config
  end
end
path_ignored?(path) click to toggle source
# File lib/tagrity/config_file.rb, line 46
def path_ignored?(path)
  excluded_paths.any? { |pat| !(/^#{pat}/ =~ path.to_s).nil? }
end
reload_global() click to toggle source
# File lib/tagrity/config_file.rb, line 19
def reload_global
  read_config(fname: global_config_path)
end
reload_local() click to toggle source
# File lib/tagrity/config_file.rb, line 15
def reload_local
  read_config(fname: local_config_path)
end
respect_git?() click to toggle source
# File lib/tagrity/config_file.rb, line 50
def respect_git?
  git_strategy != 'NA'
end
tagf() click to toggle source
# File lib/tagrity/config_file.rb, line 62
def tagf
  @config['tagf']
end
to_s() click to toggle source
# File lib/tagrity/config_file.rb, line 82
def to_s
  @config.to_s
end

Private Instance Methods

ensure_default_command() click to toggle source
# File lib/tagrity/config_file.rb, line 102
def ensure_default_command
  ensure_option('default_command', 'ctags')
end
ensure_excluded_paths() click to toggle source
# File lib/tagrity/config_file.rb, line 125
def ensure_excluded_paths
  ensure_option('excluded_paths', [])
end
ensure_extension_commands() click to toggle source
# File lib/tagrity/config_file.rb, line 98
def ensure_extension_commands
  ensure_option('extension_commands', {})
end
ensure_extensions_blacklist() click to toggle source
# File lib/tagrity/config_file.rb, line 117
def ensure_extensions_blacklist
  ensure_option('extensions_blacklist', [])
end
ensure_extensions_whitelist() click to toggle source
# File lib/tagrity/config_file.rb, line 113
def ensure_extensions_whitelist
  ensure_option('extensions_whitelist', [])
end
ensure_git_strategy() click to toggle source
# File lib/tagrity/config_file.rb, line 121
def ensure_git_strategy
  ensure_option('git_strategy', 'NA')
end
ensure_option(name, default) click to toggle source
# File lib/tagrity/config_file.rb, line 129
def ensure_option(name, default)
  if @config[name].nil? || !@config[name].is_a?(default.class)
    @config[name] = default
  end
end
ensure_tagf() click to toggle source
# File lib/tagrity/config_file.rb, line 106
def ensure_tagf
  ensure_option('tagf', 'tags')
  if File.exists?(tagf) && !File.writable?(tagf)
    raise ErrorTagFileNotWritable, "#{tagf} must be writable to be used as the tag file."
  end
end
global_config_path() click to toggle source
# File lib/tagrity/config_file.rb, line 153
def global_config_path
  File.expand_path("#{ENV['XDG_CONFIG_HOME'] || "#{ENV['HOME']}/.config"}/tagrity/#{CONFIG_FNAME}")
end
init() click to toggle source
# File lib/tagrity/config_file.rb, line 88
def init
  ensure_extension_commands
  ensure_default_command
  ensure_tagf
  ensure_extensions_whitelist
  ensure_extensions_blacklist
  ensure_git_strategy
  ensure_excluded_paths
end
local_config_path() click to toggle source
# File lib/tagrity/config_file.rb, line 157
def local_config_path
  File.expand_path("./.#{CONFIG_FNAME}")
end
logger() click to toggle source
# File lib/tagrity/config_file.rb, line 161
def logger
  @logger ||= Provider.provide(:tlogger)
end
read_config(fname: nil) click to toggle source
# File lib/tagrity/config_file.rb, line 135
def read_config(fname: nil)
  @config = {}
  config_fname = '{default configuration}'
  if fname.nil?
    if File.readable?(local_config_path)
      config_fname = local_config_path
      @config = YAML.load_file(local_config_path)
    elsif File.readable?(global_config_path)
      config_fname = global_config_path
      @config = YAML.load_file(global_config_path)
    end
  else
    @config = YAML.load_file(fname)
  end
  init
  logger.debug("Loaded config from #{config_fname} with settings #{@config.to_s}")
end