Class: SecretConfig::Providers::File

Inherits:
Provider
  • Object
show all
Defined in:
lib/secret_config/providers/file.rb

Overview

Read configuration from a local file

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Provider

#delete, #set, #to_h

Constructor Details

#initialize(file_name: "config/application.yml") ⇒ File

Returns a new instance of File.

Raises:



10
11
12
13
# File 'lib/secret_config/providers/file.rb', line 10

def initialize(file_name: "config/application.yml")
  @file_name = file_name
  raise(ConfigurationError, "Cannot find config file: #{file_name}") unless ::File.exist?(file_name)
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



8
9
10
# File 'lib/secret_config/providers/file.rb', line 8

def file_name
  @file_name
end

Instance Method Details

#each(path, &block) ⇒ Object

Yields the key with its absolute path and corresponding string value

Raises:



16
17
18
19
20
21
22
23
# File 'lib/secret_config/providers/file.rb', line 16

def each(path, &block)
  settings = fetch_path(path)

  raise(ConfigurationError, "Path #{paths.join('/')} not found in file: #{file_name}") unless settings

  Utils.flatten_each(settings, path, &block)
  nil
end

#fetch(_key) ⇒ Object

Returns the value or ‘nil` if not found



26
27
28
29
# File 'lib/secret_config/providers/file.rb', line 26

def fetch(_key)
  values = fetch_path(path)
  values.is_a?(Hash) ? nil : values
end