Class: Configy::ConfigStore

Inherits:
Object
  • Object
show all
Defined in:
lib/configy/config_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ConfigStore

Takes a Hash as input



28
29
30
# File 'lib/configy/config_store.rb', line 28

def initialize(config)
  @config = Hashie::Mash.new( config && config.to_hash || {} )
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



24
25
26
# File 'lib/configy/config_store.rb', line 24

def config
  @config
end

#mtimeObject

Returns the value of attribute mtime.



25
26
27
# File 'lib/configy/config_store.rb', line 25

def mtime
  @mtime
end

Instance Method Details

#[](key) ⇒ Object

Access to the stored configs



46
47
48
49
50
51
52
53
54
# File 'lib/configy/config_store.rb', line 46

def [](key)
  key = key.to_s

  if @config.key?(key)
    @config[key]
  else
    raise ConfigParamNotFound, key
  end
end

#compile(section) ⇒ Object

Returns a new ConfigStore by merging ‘common` with `section`



33
34
35
36
37
38
# File 'lib/configy/config_store.rb', line 33

def compile(section)
  common   = @config['common'] || {}
  selected = @config[section]  || {}

  self.class.new( common.deep_merge(selected) )
end

#merge(other) ⇒ Object

Merges two ConfigStore objects together by merging their hashes



41
42
43
# File 'lib/configy/config_store.rb', line 41

def merge(other)
  self.class.new( config.deep_merge(other.config) )
end

#to_hashObject



56
57
58
# File 'lib/configy/config_store.rb', line 56

def to_hash
  @config
end