Class: Tddium::RepoConfig

Inherits:
Object
  • Object
show all
Includes:
ConfigHelper, TddiumConstant
Defined in:
lib/tddium/cli/config.rb

Instance Method Summary collapse

Methods included from ConfigHelper

#hash_stringify_keys

Constructor Details

#initializeRepoConfig

Returns a new instance of RepoConfig.



23
24
25
26
# File 'lib/tddium/cli/config.rb', line 23

def initialize
  @scm = Tddium::SCM.configure
  @config = load_config
end

Instance Method Details

#[](key) ⇒ Object



28
29
30
# File 'lib/tddium/cli/config.rb', line 28

def [](key)
  return @config[key.to_s]
end

#config_filenameObject



32
33
34
# File 'lib/tddium/cli/config.rb', line 32

def config_filename
  @config_filename
end

#load_configObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/tddium/cli/config.rb', line 36

def load_config
  config = nil

  root = @scm.root
  cfgfile_pair = pick_config_pair(root, Config::CONFIG_PATHS)
  cfgfile_pair_depr = pick_config_pair(root, Config::CONFIG_PATHS_DEPRECATED)

  if cfgfile_pair && cfgfile_pair_depr then
    abort Text::Error::CONFIG_PATHS_COLLISION % [cfgfile_pair, cfgfile_pair_depr]
  end

  cfgfile_pair = cfgfile_pair_depr if cfgfile_pair.nil?

  if cfgfile_pair && cfgfile_pair.first then
    cfgfile = cfgfile_pair.first
    @config_filename = cfgfile_pair[1]
    begin
      rawconfig = File.read(cfgfile)
      if rawconfig && rawconfig !~ /\A\s*\z/ then
        config = YAML.load(rawconfig)
        config = hash_stringify_keys(config)
        config = config['solano'] || config['tddium'] || config
      end
    rescue Exception => e
      warn(Text::Warning::YAML_PARSE_FAILED % cfgfile)
    end
  end

  config ||= Hash.new
  return config
end