Class: CfnPP::Transform
- Inherits:
-
Object
- Object
- CfnPP::Transform
- Defined in:
- lib/cfnpp/transform.rb
Overview
This class has methods to read in cloudformation templates in YAML format with some Manta-specific extensions to make things easier.
Class Method Summary collapse
-
.load_file(path, opts = {}, name = "main", stack_url_base = "http://example.com") ⇒ Object
returns a ruby hash, from a file at
path. -
.load_yaml(yaml_txt, filebase = ".", opts = {}, name = "main", stack_url_base = "http://example.com") ⇒ Object
returns a ruby hash, from unparsed YAML input text.
Instance Method Summary collapse
-
#as_hash ⇒ Object
Return the parsed, processed CfnPP YAML file as a ruby hash.
- #as_template_result ⇒ Object
-
#initialize(in_hash, filebase = ".", opts = {}, name = "main", stack_url_base = "http://example.com") ⇒ Transform
constructor
CfnPP::Transform is initialized with a hash and an optional file base parameter.
- #lifter(h, tops, store) ⇒ Object
Constructor Details
#initialize(in_hash, filebase = ".", opts = {}, name = "main", stack_url_base = "http://example.com") ⇒ Transform
CfnPP::Transform is initialized with a hash and an optional file base parameter. The file base will default to “.”, which may or may not be what you want.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cfnpp/transform.rb', line 35 def initialize(in_hash, filebase=".", opts={}, name="main", stack_url_base="http://example.com") @name = name @opts = opts @filebase = filebase @stack_url_base = stack_url_base @in_hash = { :root => in_hash } @tops = self.class.stdtops() trans_hash(@in_hash) @in_hash = @in_hash[:root] @substacks = grab_stacks(@in_hash) lift @in_hash = apply_opts(@in_hash, opts) prune(@in_hash) end |
Class Method Details
.load_file(path, opts = {}, name = "main", stack_url_base = "http://example.com") ⇒ Object
returns a ruby hash, from a file at path
This is the easiest way to load things. It takes care of setting reasonable file base for includes, etc., and gives you back a hash ready for use.
21 22 23 |
# File 'lib/cfnpp/transform.rb', line 21 def self.load_file(path, opts = {}, name = "main", stack_url_base="http://example.com") return self.load_yaml(File.read(path), path, opts, name, stack_url_base) end |
.load_yaml(yaml_txt, filebase = ".", opts = {}, name = "main", stack_url_base = "http://example.com") ⇒ Object
returns a ruby hash, from unparsed YAML input text.
27 28 29 30 |
# File 'lib/cfnpp/transform.rb', line 27 def self.load_yaml(yaml_txt, filebase=".", opts={}, name = "main", stack_url_base="http://example.com") h = YAML::load(yaml_txt) return self.new(h, filebase, opts, name, stack_url_base).as_template_result end |
Instance Method Details
#as_hash ⇒ Object
Return the parsed, processed CfnPP YAML file as a ruby hash
51 52 53 |
# File 'lib/cfnpp/transform.rb', line 51 def as_hash return @in_hash end |
#as_template_result ⇒ Object
55 56 57 |
# File 'lib/cfnpp/transform.rb', line 55 def as_template_result return CfnPP::TemplateResult.new(@name, @in_hash, @stack_url_base, @substacks) end |
#lifter(h, tops, store) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/cfnpp/transform.rb', line 237 def lifter(h, tops, store) # this guard is a super ugly hacky if h.has_key? 'Type' and h['Type'] == 'AWS::CloudFormation::Stack' return end h.keys.each do |key| if h[key].is_a? Hash lifter(h[key], tops, store) elsif h[key].is_a? Array h[key].each do |e| if e.is_a? Hash lifter(e, tops, store) end end end if tops.include? key if (not store[key]) store[key] = [] end store[key].push h.delete(key) end end end |