Class: Dacs::FileSource

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/dacs/file_source.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_path, environment) ⇒ FileSource

Returns a new instance of FileSource.



11
12
13
14
# File 'lib/dacs/file_source.rb', line 11

def initialize(config_path, environment)
  @path        = Pathname(config_path)
  @environment = environment.to_s
end

Instance Method Details

#eachObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dacs/file_source.rb', line 20

def each
  @path.open('r') do |f|
    environments = YAML.load(f)
    environment = environments.fetch(@environment) do
    raise ConfigurationError, 
      "File #{@path} contains no #{environment} section"
    end
    environment.each_pair do |key, value|
      yield ConfiguredValue.new(self, key.to_s, value)
    end
  end
end

#to_sObject



16
17
18
# File 'lib/dacs/file_source.rb', line 16

def to_s
  "file #{@path.relative_path_from(Pathname.pwd).to_s}"
end