Class: Chamber::Keys::Base
- Inherits:
-
Object
- Object
- Chamber::Keys::Base
- Defined in:
- lib/chamber/keys/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#filenames ⇒ Object
readonly
Returns the value of attribute filenames.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
-
#rootpath ⇒ Object
Returns the value of attribute rootpath.
Class Method Summary collapse
Instance Method Summary collapse
- #as_environment_variables ⇒ Object
-
#initialize(rootpath:, namespaces:, filenames: nil) ⇒ Base
constructor
A new instance of Base.
- #resolve ⇒ Object
Constructor Details
#initialize(rootpath:, namespaces:, filenames: nil) ⇒ Base
Returns a new instance of Base.
14 15 16 17 18 |
# File 'lib/chamber/keys/base.rb', line 14 def initialize(rootpath:, namespaces:, filenames: nil) self.rootpath = Pathname.new(rootpath) self.namespaces = namespaces self.filenames = filenames end |
Instance Attribute Details
#filenames ⇒ Object
Returns the value of attribute filenames.
7 8 9 |
# File 'lib/chamber/keys/base.rb', line 7 def filenames @filenames end |
#namespaces ⇒ Object
Returns the value of attribute namespaces.
7 8 9 |
# File 'lib/chamber/keys/base.rb', line 7 def namespaces @namespaces end |
#rootpath ⇒ Object
Returns the value of attribute rootpath.
6 7 8 |
# File 'lib/chamber/keys/base.rb', line 6 def rootpath @rootpath end |
Class Method Details
.resolve(**args) ⇒ Object
10 11 12 |
# File 'lib/chamber/keys/base.rb', line 10 def self.resolve(**args) new(**args).resolve end |
Instance Method Details
#as_environment_variables ⇒ Object
33 34 35 36 37 |
# File 'lib/chamber/keys/base.rb', line 33 def as_environment_variables key_paths.select(&:readable?).each_with_object({}) do |path, memo| memo[environment_variable_from_path(path)] = path.read end end |
#resolve ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/chamber/keys/base.rb', line 20 def resolve key_paths.each_with_object({}) do |path, memo| namespace = namespace_from_path(path) || '__default' value = if path.readable? path.read else ENV.fetch(environment_variable_from_path(path), nil) end memo[namespace.downcase.to_sym] = value if value end end |