Class: Dacs::FileSource

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

Instance Method Summary collapse

Constructor Details

#initialize(config_path, environment) ⇒ FileSource

Returns a new instance of FileSource.



6
7
8
9
# File 'lib/dacs/file_source.rb', line 6

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

Instance Method Details

#eachObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dacs/file_source.rb', line 15

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



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

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