Class: Chamber::Keys::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/chamber/keys/base.rb

Direct Known Subclasses

Decryption, Encryption

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#filenamesObject

Returns the value of attribute filenames.



7
8
9
# File 'lib/chamber/keys/base.rb', line 7

def filenames
  @filenames
end

#namespacesObject

Returns the value of attribute namespaces.



7
8
9
# File 'lib/chamber/keys/base.rb', line 7

def namespaces
  @namespaces
end

#rootpathObject

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_variablesObject



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

#resolveObject



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