Class: SecretConfig::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/secret_config/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, registry, interpolate: true) ⇒ Parser

Returns a new instance of Parser.



5
6
7
8
9
10
11
12
# File 'lib/secret_config/parser.rb', line 5

def initialize(path, registry, interpolate: true)
  @path         = path
  @registry     = registry
  @fetch_list   = {}
  @import_list  = {}
  @tree         = {}
  @interpolator = interpolate ? SettingInterpolator.new : nil
end

Instance Attribute Details

#interpolatorObject (readonly)

Returns the value of attribute interpolator.



3
4
5
# File 'lib/secret_config/parser.rb', line 3

def interpolator
  @interpolator
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/secret_config/parser.rb', line 3

def path
  @path
end

#registryObject (readonly)

Returns the value of attribute registry.



3
4
5
# File 'lib/secret_config/parser.rb', line 3

def registry
  @registry
end

#treeObject (readonly)

Returns the value of attribute tree.



3
4
5
# File 'lib/secret_config/parser.rb', line 3

def tree
  @tree
end

Instance Method Details

#parse(key, value) ⇒ Object

Returns a flat path of keys and values from the provider without looking in the local path. Keys are returned with path names relative to the supplied path.



16
17
18
19
20
# File 'lib/secret_config/parser.rb', line 16

def parse(key, value)
  relative_key       = relative_key?(key) ? key : key.sub("#{path}/", "")
  value              = interpolator.parse(value) if interpolator && value.is_a?(String) && value.include?("${")
  tree[relative_key] = value
end

#renderObject

Returns a flat Hash of the rendered paths.



23
24
25
26
# File 'lib/secret_config/parser.rb', line 23

def render
  apply_imports if interpolator
  tree
end