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
-
#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
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/secret_config/providers/file.rb', line 15 def each(path, &block) config = YAML.load(ERB.new(::File.new(file_name).read).result) paths = path.sub(%r{\A/*}, "").sub(%r{/*\Z}, "").split("/") settings = config.dig(*paths) raise(ConfigurationError, "Path #{paths.join('/')} not found in file: #{file_name}") unless settings Utils.flatten_each(settings, path, &block) nil end |