Class: Konfig::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/konfig/store.rb

Instance Method Summary collapse

Constructor Details

#initializeStore

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

Parameters:

  • key (String, Symbol)


41
42
43
# File 'lib/konfig/store.rb', line 41

def [](key)
  @data[key]
end

#dataObject



49
50
51
# File 'lib/konfig/store.rb', line 49

def data
  @data
end

#inspectObject



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.

Parameters:

  • path (String)

    to directory



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

Parameters:

  • path (String)

    to file



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