Class: SecretConfig::Providers::File
- Defined in:
- lib/secret_config/providers/file.rb
Overview
Read configuration from a local file
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Instance Method Summary collapse
-
#each(path, &block) ⇒ Object
Yields the key with its absolute path and corresponding string value.
-
#fetch(_key) ⇒ Object
Returns the value or ‘nil` if not found.
-
#initialize(file_name: "config/application.yml") ⇒ File
constructor
A new instance of File.
Methods inherited from Provider
Constructor Details
#initialize(file_name: "config/application.yml") ⇒ File
Returns a new instance of File.
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_name ⇒ Object (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
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 |