Class: Konfig::Sources::Directory
- Defined in:
- lib/konfig/sources/directory.rb
Instance Method Summary collapse
- #get(path, attribute: nil) ⇒ Object
-
#initialize(root, strip_contents: true, array_separator: /\n/) ⇒ Directory
constructor
A new instance of Directory.
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 |