Module: CloudFormationTool::CLI::ParamSupport

Included in:
Compile, Create
Defined in:
lib/cloud_formation_tool/cli/param_support.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(o) ⇒ Object



8
9
10
# File 'lib/cloud_formation_tool/cli/param_support.rb', line 8

def self.included o
  o.extend ClassMethods
end

Instance Method Details

#get_paramsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cloud_formation_tool/cli/param_support.rb', line 38

def get_params
  params = if param_file
    yaml = YAML.load(read_param_file(param_file), filename: param_file, permitted_classes: [Date, Symbol]).to_h
    if param_key
      raise "Missing parameter section '#{param_key}' in '#{param_file}'!" unless yaml[param_key].is_a? Hash
      yaml[param_key]
    else
      yaml
    end
  else
    Hash.new
  end
  # allow param_list to override parameters from the param file
  param_list.inject(params) do |h, param|
    k,v = param.split /\s*[=:]\s*/
    h[k] = v
    h
  end
end

#read_param_file(file) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/cloud_formation_tool/cli/param_support.rb', line 28

def read_param_file(file)
  param_uri = URI(file)
  case param_uri.scheme
  when /^http/
    Net::HTTP.get(param_uri)
  else
    File.read(file)
  end
end