Class: CfnDsl::ExternalParameters

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cfndsl/external_parameters.rb

Overview

Handles all external parameters

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExternalParameters

Returns a new instance of ExternalParameters.



32
33
34
# File 'lib/cfndsl/external_parameters.rb', line 32

def initialize
  @parameters = self.class.defaults.clone
end

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters.



14
15
16
# File 'lib/cfndsl/external_parameters.rb', line 14

def parameters
  @parameters
end

Class Method Details

.currentObject



23
24
25
# File 'lib/cfndsl/external_parameters.rb', line 23

def current
  @current || refresh!
end

.defaults(params = {}) ⇒ Object



17
18
19
20
21
# File 'lib/cfndsl/external_parameters.rb', line 17

def defaults(params = {})
  @defaults ||= {}
  @defaults.merge! params
  @defaults
end

.refresh!Object



27
28
29
# File 'lib/cfndsl/external_parameters.rb', line 27

def refresh!
  @current = new
end

Instance Method Details

#get_param(key) ⇒ Object Also known as: []



44
45
46
# File 'lib/cfndsl/external_parameters.rb', line 44

def get_param(key)
  parameters[key.to_sym]
end

#load_file(fname) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cfndsl/external_parameters.rb', line 53

def load_file(fname)
  format = File.extname fname
  case format
  when /ya?ml/
    params = YAML.load_file fname
  when /json/
    params = JSON.parse File.read(fname)
  else
    raise "Unrecognized extension #{format}"
  end
  if CfnDsl.disable_deep_merge?
    params.each { |key, val| set_param(key, val) }
  else
    x = {}
    params.map { |k, v| x[k.to_sym] = v }
    merge_param(x)
  end
end

#merge_param(xray) ⇒ Object



40
41
42
# File 'lib/cfndsl/external_parameters.rb', line 40

def merge_param(xray)
  parameters.deep_merge!(xray)
end

#set_param(key, val) ⇒ Object



36
37
38
# File 'lib/cfndsl/external_parameters.rb', line 36

def set_param(key, val)
  parameters[key.to_sym] = val
end

#to_hObject



49
50
51
# File 'lib/cfndsl/external_parameters.rb', line 49

def to_h
  parameters
end