Class: Solano::RepoConfig
- Inherits:
-
Object
- Object
- Solano::RepoConfig
- Includes:
- ConfigHelper, SolanoConstant
- Defined in:
- lib/solano/cli/config.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #config_filename ⇒ Object
-
#initialize(scm) ⇒ RepoConfig
constructor
A new instance of RepoConfig.
- #load_config ⇒ Object
- #read_config(raise_error) ⇒ Object
Methods included from ConfigHelper
Constructor Details
#initialize(scm) ⇒ RepoConfig
Returns a new instance of RepoConfig.
10 11 12 13 |
# File 'lib/solano/cli/config.rb', line 10 def initialize(scm) @scm = scm @config = load_config end |
Instance Method Details
#[](key) ⇒ Object
15 16 17 |
# File 'lib/solano/cli/config.rb', line 15 def [](key) return @config[key.to_s] end |
#config_filename ⇒ Object
19 20 21 |
# File 'lib/solano/cli/config.rb', line 19 def config_filename @config_filename end |
#load_config ⇒ Object
23 24 25 26 |
# File 'lib/solano/cli/config.rb', line 23 def load_config config, raw_config = read_config(false) return config end |
#read_config(raise_error) ⇒ Object
28 29 30 31 32 33 34 35 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 |
# File 'lib/solano/cli/config.rb', line 28 def read_config(raise_error) config = nil raw_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 raw_config = File.read(cfgfile) if raw_config && raw_config !~ /\A\s*\z/ then config = YAML.load(raw_config) config = hash_stringify_keys(config) config = config['solano'] || config['tddium'] || config end rescue Exception => e = Text::Warning::YAML_PARSE_FAILED % cfgfile if raise_error then raise ::Solano::SolanoError.new() else say end end end config ||= Hash.new raw_config ||= '' return [config, raw_config] end |