Module: CfnDsl

Defined in:
lib/cfndsl.rb,
lib/cfndsl/names.rb,
lib/cfndsl/types.rb,
lib/cfndsl/errors.rb,
lib/cfndsl/outputs.rb,
lib/cfndsl/plurals.rb,
lib/cfndsl/version.rb,
lib/cfndsl/jsonable.rb,
lib/cfndsl/mappings.rb,
lib/cfndsl/metadata.rb,
lib/cfndsl/os/types.rb,
lib/cfndsl/aws/types.rb,
lib/cfndsl/rake_task.rb,
lib/cfndsl/resources.rb,
lib/cfndsl/conditions.rb,
lib/cfndsl/parameters.rb,
lib/cfndsl/properties.rb,
lib/cfndsl/update_policy.rb,
lib/cfndsl/generate_types.rb,
lib/cfndsl/creation_policy.rb,
lib/cfndsl/os/heat_template.rb,
lib/cfndsl/orchestration_template.rb,
lib/cfndsl/aws/cloud_formation_template.rb

Overview

Method name helper

Defined Under Namespace

Modules: AWS, Errors, Functions, GenerateTypes, OS, Plurals, Types Classes: CloudFormationTemplate, ConditionDefinition, CreationPolicyDefinition, Fn, HeatTemplate, JSONable, MappingDefinition, MetadataDefinition, OrchestrationTemplate, OutputDefinition, ParameterDefinition, PropertyDefinition, RakeTask, RefDefinition, ResourceDefinition, UpdatePolicyDefinition

Constant Summary collapse

VERSION =
'0.5.2'.freeze

Class Method Summary collapse

Class Method Details

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

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.



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
# File 'lib/cfndsl.rb', line 51

def self.eval_file_with_extras(filename, extras = [], logstream = nil)
  b = binding
  extras.each do |pair|
    type, file = pair
    case type
    when :yaml, :json
      klass_name = type.to_s.upcase
      klass = Object.const_get(klass_name)
      logstream.puts("Loading #{klass_name} file #{file}") if logstream
      parameters = klass.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)

  model
end

.method_names(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.method_names(name, &block)
  if block
    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