Module: Config

Extended by:
Constants
Defined in:
lib/pangea/cli/config.rb

Constant Summary

Constants included from Constants

Constants::ARTIFACT_FILE, Constants::CACHE_DIR, Constants::EXTENSIONS, Constants::PROJECT_SRC_DIRS, Constants::PROJECT_VERSION

Class Method Summary collapse

Class Method Details

.default_pathsObject

return array of paths that can store a configuration



20
21
22
23
24
25
26
27
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pangea/cli/config.rb', line 20

def default_paths
  paths = {}

  # configuration files to look for
  EXTENSIONS.each do |ext|
    paths[ext] = [] unless paths[ext]

    ###############################
    # system level configuration
    ###############################

    paths[ext] << File.join(%(/etc), %(pangea), %(pangea.#{ext}))
    paths[ext].concat(
      Dir.glob(
        File.join(%(/etc/), %(pangea), %(conf.d), %(*.#{ext}))
      )
    )

    # end system level configuration

    ###############################
    # home configuration
    ###############################

    paths[ext] << File.join(xdg_config_home, %(pangea), %(pangea.#{ext}))
    paths[ext].concat(
      Dir.glob(
        File.join(xdg_config_home, %(pangea), %(conf.d), %(*.#{ext}))
      )
    )

    # end home configuration

    ###############################
    # local configuration
    ###############################

    paths[ext] << %(pangea.#{ext})
    paths[ext] << Dir.glob(
      File.join(
        %(pangea),
        %(conf.d),
        %(*.#{ext})
      )
    )

    # end local configuration
  end

  # only return existing files
  res = []
  EXTENSIONS.each do |ext|
    files = paths[ext]
    files.each do |file|
      res << file if File.exist?(file.to_s)
    end
  end

  res
end

.resolve_configurations(ignore_default_paths: false, extra_paths: []) ⇒ Object

read file paths and run configuration parsers then appropriately merge configurations



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pangea/cli/config.rb', line 83

def resolve_configurations(ignore_default_paths: false, extra_paths: [])
  paths = if ignore_default_paths
            extra_paths
          else
            default_paths.concat(extra_paths)
          end
  paths.each do |path|
    parted  = path.split(%(.))
    ext     = parted[-1]
    _base   = parted[0]

    synthesizer.synthesize(File.read(path), ext)
  end
  synthesizer.synthesis
end

.synthesizerObject



8
9
10
# File 'lib/pangea/cli/config.rb', line 8

def synthesizer
  @synthesizer ||= ConfigSynthesizer.new
end

.xdg_config_homeObject



12
13
14
15
16
17
# File 'lib/pangea/cli/config.rb', line 12

def xdg_config_home
  ENV.fetch(
    %(XDG_CONFIG_HOME),
    %(#{ENV.fetch('HOME', nil)}/.config)
  )
end