Class: SecretConfig::Providers::File

Inherits:
Object
  • 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

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

Raises:

  • (ConfigError)


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

Raises:

  • (NotImplementedError)


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

def set(key, value)
  raise NotImplementedError
end