class CsvCop::ConfigLoader

Constants

CSVCOP_HOME
DEFAULT_FILE
DOTFILE

Public Class Methods

new(rule_file_path=nil) click to toggle source
# File lib/csvcop/config_loader.rb, line 12
def initialize(rule_file_path=nil)
  unless rule_file_path.nil?
    raise ConfigNotFoundError unless File.exist?(rule_file_path)
    @original_rule = YAML.load_file(rule_file_path)
  end
  @rule = YAML.load_file(DEFAULT_FILE)
end

Public Instance Methods

load() click to toggle source
# File lib/csvcop/config_loader.rb, line 20
def load
  return @rule if @original_rule.nil?
  merge_yaml(@rule, @original_rule)
end

Private Instance Methods

merge_yaml(yaml1, yaml2) click to toggle source
# File lib/csvcop/config_loader.rb, line 27
def merge_yaml(yaml1, yaml2)
  yaml2.each do |k, v|
    if v.class == Hash && yaml1.key?(k)
      yaml1[k] = merge_yaml(yaml1[k], v)
    else
      yaml1[k] = v
    end
  end
  return yaml1
end