Class: Konfig::Sources::Directory

Inherits:
Abstract
  • Object
show all
Defined in:
lib/konfig/sources/directory.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, strip_contents: true, array_separator: /\n/) ⇒ Directory

Returns a new instance of Directory.



10
11
12
13
14
15
# File 'lib/konfig/sources/directory.rb', line 10

def initialize(root, strip_contents: true, array_separator: /\n/)
  super()
  @root = root
  @strip_contents = strip_contents
  @array_separator = array_separator
end

Instance Method Details

#get(path, attribute: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/konfig/sources/directory.rb', line 17

def get(path, attribute: nil)
  file_path = File.join(@root, path.join('.'))
  raise ValueNotPresentError unless File.exist?(file_path)

  result = File.read(file_path)
  result = result.strip if @strip_contents
  result = handle_array(result) if attribute&.array?
  result
end