Module: CfnDsl

Defined in:
lib/cfndsl.rb,
lib/cfndsl/Types.rb,
lib/cfndsl/names.rb,
lib/cfndsl/Errors.rb,
lib/cfndsl/Outputs.rb,
lib/cfndsl/Plurals.rb,
lib/cfndsl/JSONable.rb,
lib/cfndsl/Mappings.rb,
lib/cfndsl/Metadata.rb,
lib/cfndsl/Resources.rb,
lib/cfndsl/Conditions.rb,
lib/cfndsl/Parameters.rb,
lib/cfndsl/Properties.rb,
lib/cfndsl/UpdatePolicy.rb,
lib/cfndsl/CreationPolicy.rb,
lib/cfndsl/CloudFormationTemplate.rb

Defined Under Namespace

Modules: AWSTypes, Errors, Functions, OSTypes, Plurals Classes: CloudFormationTemplate, ConditionDefinition, CreationPolicyDefinition, Fn, HeatTemplate, JSONable, MappingDefinition, MetadataDefinition, OrchestrationTemplate, OutputDefinition, ParameterDefinition, PropertyDefinition, RefDefinition, ResourceDefinition, UpdatePolicyDefinition

Class Method Summary collapse

Class Method Details

.eval_file_with_extras(filename, extras = [], logstream = nil) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cfndsl.rb', line 20

def self.eval_file_with_extras(filename, extras = [], logstream = nil)
  # This function handles the eval of the template file and returns the
  # results. It does this with a ruby "eval", but it builds up a customized
  # binding environment before it calls eval. The environment can be
  # customized by passing a list of customizations in the extras parameter.
  #
  # These customizations are expressed as an array of pairs of
  # (type,filename). They are evaluated in the order they appear in the
  # extras array. The types are as follows
  #
  # :yaml - the second element is treated as a file name, which is loaded
  #         as a yaml file. The yaml file should contain a top level
  #         dictionary. Each of the keys of the top level dictionary is
  #         used as a local variable in the evalation context.
  #
  # :json - the second element is treated as a file name, which is loaded
  #         as a json file. The yaml file should contain a top level
  #         dictionary. Each of the keys of the top level dictionary is
  #         used as a local variable in the evalation context.
  #
  # :ruby - the second element is treated as a file name which is evaluated
  #         as a ruby file. Any assigments (or other binding affecting
  #         side effects) will persist into the context where the template
  #         is evaluated
  #
  # :raw  - the seccond elements is treated as a ruby statement and is
  #         evaluated in the binding context, similar to the contents of
  #         a ruby file.
  #
  # Note that the order is important, as later extra sections can overwrite
  # or even undo things that were done by earlier sections.

  b = binding
  extras.each do |pair|
    type,file = pair
    case type
    when :yaml
      logstream.puts("Loading YAML file #{file}") if logstream
      parameters = YAML.load(File.read(file))
      parameters.each do |k,v|
        logstream.puts("Setting local variable #{k} to #{v}") if logstream
        b.eval("#{k} = #{v.inspect}")
      end

    when :json
      logstream.puts("Loading YAML file #{file}") if logstream
      parameters = JSON.load(File.read(file))
      parameters.each do |k,v|
        logstream.puts("Setting local variable #{k} to #{v}") if logstream
        b.eval("#{k} = #{v.inspect}")
      end

    when :ruby
      logstream.puts("Runnning ruby file #{file}") if logstream
      b.eval(File.read(file), file)

    when :raw
      logstream.puts("Running raw ruby code #{file}") if logstream
      b.eval(file, "raw code")
    end
  end

  logstream.puts("Loading template file #{filename}") if logstream
  model = b.eval(File.read(filename), filename)
  return model
end

.methodNames(name, &block) ⇒ Object

iterates through the the valid case-insensitive names for “name”.


5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cfndsl/names.rb', line 5

def self.methodNames(name, &block)
  if block then
    name_str = name.to_s
    yield name_str.to_sym
    n = name_str.dup
    n[0] = n[0].swapcase
    yield n.to_sym
  else
    result = [name.dup,name.dup]
    result[1][0] = result[1][0].swapcase
    return result
  end
end