Class: CfnDsl::JSONable

Inherits:
Object
  • Object
show all
Extended by:
Functions
Includes:
Functions, RefCheck
Defined in:
lib/cfndsl/jsonable.rb

Overview

This is the base class for just about everything useful in the DSL. It knows how to turn DSL Objects into the corresponding json, and it lets you create new built in function objects from inside the context of a dsl object.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Functions

FnAnd, FnBase64, FnEquals, FnFindInMap, FnFormat, FnGetAZs, FnGetAtt, FnIf, FnImportValue, FnJoin, FnNot, FnOr, FnSelect, FnSub, Ref

Methods included from RefCheck

#build_references

Class Method Details

.external_parametersObject



155
156
157
# File 'lib/cfndsl/jsonable.rb', line 155

def self.external_parameters
  CfnDsl::ExternalParameters.current
end

Instance Method Details

#as_json(_options = {}) ⇒ Object

Use instance variables to build a json object. Instance variables that begin with a single underscore are elided. Instance variables that begin with two underscores have one of them removed.



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/cfndsl/jsonable.rb', line 167

def as_json(_options = {})
  hash = {}
  instance_variables.each do |var|
    name = var[1..-1]

    if name =~ /^__/
      # if a variable starts with double underscore, strip one off
      name = name[1..-1]
    elsif name =~ /^_/
      # Hide variables that start with single underscore
      name = nil
    end

    hash[name] = instance_variable_get(var) if name
  end
  hash
end

#declare(&block) ⇒ Object



193
194
195
# File 'lib/cfndsl/jsonable.rb', line 193

def declare(&block)
  instance_eval(&block) if block_given?
end

#external_parametersObject



159
160
161
# File 'lib/cfndsl/jsonable.rb', line 159

def external_parameters
  self.class.external_parameters
end

#ref_childrenObject



189
190
191
# File 'lib/cfndsl/jsonable.rb', line 189

def ref_children
  instance_variables.map { |var| instance_variable_get(var) }
end

#to_json(*a) ⇒ Object



185
186
187
# File 'lib/cfndsl/jsonable.rb', line 185

def to_json(*a)
  as_json.to_json(*a)
end