Class: SugarJar::RepoConfig

Inherits:
Object
  • Object
show all
Extended by:
Util
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

Methods included from Util

gh, gh_nofail, git, git_nofail, hub, hub_nofail, in_repo, repo_name, repo_root, which, which_nofail

Class Method Details

.config(config = CONFIG_NAME) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sugarjar/repoconfig.rb', line 28

def self.config(config = CONFIG_NAME)
  data = {}
  unless 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

Returns:

  • (Boolean)


24
25
26
# File 'lib/sugarjar/repoconfig.rb', line 24

def self.config_file?(config_file)
  File.exist?(config_file)
end

.hash_from_file(config_file) ⇒ Object



18
19
20
21
# File 'lib/sugarjar/repoconfig.rb', line 18

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



14
15
16
# File 'lib/sugarjar/repoconfig.rb', line 14

def self.repo_config_path(config)
  ::File.join(repo_root, config)
end