Class: CfnDsl::ExternalParameters
- Inherits:
-
Object
- Object
- CfnDsl::ExternalParameters
- Extended by:
- Forwardable
- Defined in:
- lib/cfndsl/external_parameters.rb
Overview
Handles all external parameters
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
- #add_to_binding(bind, logstream) ⇒ Object
- #get_param(k) ⇒ Object (also: #[])
-
#initialize ⇒ ExternalParameters
constructor
A new instance of ExternalParameters.
- #load_file(fname) ⇒ Object
- #set_param(k, v) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ ExternalParameters
Returns a new instance of ExternalParameters.
10 11 12 |
# File 'lib/cfndsl/external_parameters.rb', line 10 def initialize @parameters = {} end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
8 9 10 |
# File 'lib/cfndsl/external_parameters.rb', line 8 def parameters @parameters end |
Instance Method Details
#add_to_binding(bind, logstream) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/cfndsl/external_parameters.rb', line 27 def add_to_binding(bind, logstream) parameters.each_pair do |key, val| logstream.puts("Setting local variable #{key} to #{val}") if logstream bind.eval "#{key} = #{val.inspect}" end end |
#get_param(k) ⇒ Object Also known as: []
18 19 20 |
# File 'lib/cfndsl/external_parameters.rb', line 18 def get_param(k) parameters[k.to_sym] end |
#load_file(fname) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cfndsl/external_parameters.rb', line 34 def load_file(fname) format = File.extname fname case format when /ya?ml/ params = YAML.load_file fname when /json/ params = JSON.load File.read(fname) else raise "Unrecognized extension #{format}" end params.each { |key, val| set_param(key, val) } end |
#set_param(k, v) ⇒ Object
14 15 16 |
# File 'lib/cfndsl/external_parameters.rb', line 14 def set_param(k, v) parameters[k.to_sym] = v end |
#to_h ⇒ Object
23 24 25 |
# File 'lib/cfndsl/external_parameters.rb', line 23 def to_h parameters end |