Class: SecretConfig::Providers::File
- Inherits:
-
Object
- Object
- 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.
- #set(key, value) ⇒ Object
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(/\A\/*/, '').sub(/\/*\Z/, '').split("/") settings = config.dig(*paths) raise(ConfigError, "Path #{paths.join(".")} not found in file: #{file_name}") unless settings flatten_each(path, settings, &block) nil end |
#set(key, value) ⇒ Object
27 28 29 |
# File 'lib/secret_config/providers/file.rb', line 27 def set(key, value) raise NotImplementedError end |