Class: Greener::ConfigStore

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/greener/config_store.rb

Overview

Read configs from a user-specified greener.yml or fallback to defaults

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#checker_from_string, #formatter_from_string

Constructor Details

#initialize(path, default_path = nil) ⇒ ConfigStore

Returns a new instance of ConfigStore.



22
23
24
25
26
27
28
29
30
# File 'lib/greener/config_store.rb', line 22

def initialize(path, default_path = nil)
  @path = path
  default_path ||= default_absolute_path
  @default_path = default_path

  @checkers = {}
  @files = []
  @formatters = []
end

Instance Attribute Details

#checkersObject (readonly)

Returns the value of attribute checkers.



20
21
22
# File 'lib/greener/config_store.rb', line 20

def checkers
  @checkers
end

#filesObject (readonly)

Returns the value of attribute files.



20
21
22
# File 'lib/greener/config_store.rb', line 20

def files
  @files
end

#formattersObject (readonly)

Returns the value of attribute formatters.



20
21
22
# File 'lib/greener/config_store.rb', line 20

def formatters
  @formatters
end

Instance Method Details

#files_matching_glob(glob) ⇒ Object



51
52
53
# File 'lib/greener/config_store.rb', line 51

def files_matching_glob(glob)
  Dir.glob(glob).select { |e| File.file? e }
end

#load_yml_file(path) ⇒ Object

Stub-able methods



47
48
49
# File 'lib/greener/config_store.rb', line 47

def load_yml_file(path)
  YAML.load_file(path)
end

#resolveObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/greener/config_store.rb', line 32

def resolve
  if @path
    fail Error::Standard, "No config file found at specified path: #{@path}" unless File.exist? @path
    config = load_yml_file @path
  end

  config ||= {}
  defaults = load_yml_file @default_path
  @all = merge_hashes(defaults, config)

  validate
  self
end