Class: Konfig::Store
- Inherits:
-
Object
- Object
- Konfig::Store
- Defined in:
- lib/konfig/store.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Hash-style access to data.
- #data ⇒ Object
-
#initialize ⇒ Store
constructor
A new instance of Store.
- #inspect ⇒ Object
-
#load_directory(path) ⇒ Object
Loads all yml files in a directory into this store Will not recurse into subdirectories.
-
#load_file(path) ⇒ Object
Loads a single yml file into the store.
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
9 10 11 |
# File 'lib/konfig/store.rb', line 9 def initialize @data = HashWithIndifferentAccess.new end |
Instance Method Details
#[](key) ⇒ Object
Hash-style access to data
41 42 43 |
# File 'lib/konfig/store.rb', line 41 def [](key) @data[key] end |
#data ⇒ Object
49 50 51 |
# File 'lib/konfig/store.rb', line 49 def data @data end |
#inspect ⇒ Object
45 46 47 |
# File 'lib/konfig/store.rb', line 45 def inspect @data.inspect end |
#load_directory(path) ⇒ Object
Loads all yml files in a directory into this store Will not recurse into subdirectories.
16 17 18 19 20 21 22 23 |
# File 'lib/konfig/store.rb', line 16 def load_directory(path) unless File.directory?(path) raise "Konfig couldn't load because it was unable to access #{ path }. Please make sure the directory exists and has the correct permissions." end Dir[File.join(path, "*.yml")].each { |f| load_file(f) } end |
#load_file(path) ⇒ Object
Loads a single yml file into the store
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/konfig/store.rb', line 27 def load_file(path) d = YAML.load_file(path) if d.is_a?(Hash) d = HashWithIndifferentAccess.new(d) e = Evaluator.new(d) d = process(d, e) end @data[File.basename(path, ".yml").downcase] = d end |