Class: SugarJar::RepoConfig
- Inherits:
-
Object
- Object
- SugarJar::RepoConfig
- Defined in:
- lib/sugarjar/repoconfig.rb
Overview
This parses SugarJar repoconfigs (not to be confused with configs). This is lint/unit/on_push configs.
Constant Summary collapse
- CONFIG_NAME =
'.sugarjar.yaml'.freeze
Class Method Summary collapse
- .config(config = CONFIG_NAME) ⇒ Object
-
.config_file?(config_file) ⇒ Boolean
wrapper for File.exist to make unittests easier.
- .hash_from_file(config_file) ⇒ Object
- .repo_config_path(config) ⇒ Object
Class Method Details
.config(config = CONFIG_NAME) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sugarjar/repoconfig.rb', line 26 def self.config(config = CONFIG_NAME) data = {} unless SugarJar::Util.in_repo? SugarJar::Log.debug('Not in repo, skipping repoconfig load') return data end config_file = repo_config_path(config) data = hash_from_file(config_file) if config_file?(config_file) if data['overwrite_from'] && config_file?(data['overwrite_from']) SugarJar::Log.debug( "Attempting overwrite_from #{data['overwrite_from']}", ) data = config(data['overwrite_from']) data.delete('overwrite_from') elsif data['include_from'] && config_file?(data['include_from']) SugarJar::Log.debug("Attempting include_from #{data['include_from']}") data.deep_merge!(config(data['include_from'])) data.delete('include_from') end data end |
.config_file?(config_file) ⇒ Boolean
wrapper for File.exist to make unittests easier
22 23 24 |
# File 'lib/sugarjar/repoconfig.rb', line 22 def self.config_file?(config_file) File.exist?(config_file) end |
.hash_from_file(config_file) ⇒ Object
16 17 18 19 |
# File 'lib/sugarjar/repoconfig.rb', line 16 def self.hash_from_file(config_file) SugarJar::Log.debug("Loading repo config: #{config_file}") YAML.safe_load_file(config_file) end |
.repo_config_path(config) ⇒ Object
12 13 14 |
# File 'lib/sugarjar/repoconfig.rb', line 12 def self.repo_config_path(config) ::File.join(SugarJar::Util.repo_root, config) end |