Class: Greener::ConfigStore
- Inherits:
-
Object
- Object
- Greener::ConfigStore
- 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
-
#checkers ⇒ Object
readonly
Returns the value of attribute checkers.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#formatters ⇒ Object
readonly
Returns the value of attribute formatters.
Instance Method Summary collapse
- #files_matching_glob(glob) ⇒ Object
-
#initialize(path, default_path = nil) ⇒ ConfigStore
constructor
A new instance of ConfigStore.
-
#load_yml_file(path) ⇒ Object
Stub-able methods.
- #resolve ⇒ Object
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
#checkers ⇒ Object (readonly)
Returns the value of attribute checkers.
20 21 22 |
# File 'lib/greener/config_store.rb', line 20 def checkers @checkers end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
20 21 22 |
# File 'lib/greener/config_store.rb', line 20 def files @files end |
#formatters ⇒ Object (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 |
#resolve ⇒ Object
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 |