class CfnDsl::JSONable
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.
Public Class Methods
Source
# File lib/cfndsl/jsonable.rb, line 123 def self.external_parameters CfnDsl::ExternalParameters.current end
Public Instance Methods
Source
# File lib/cfndsl/jsonable.rb, line 135 def as_json(_options = {}) check_names hash = {} instance_variables.each do |var| name = var[1..] case name when /^__/ # if a variable starts with double underscore, strip one off name = name[1..] when /^_/ # Hide variables that start with single underscore name = nil end hash[name] = instance_variable_get(var) if name end hash end
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.
Source
# File lib/cfndsl/jsonable.rb, line 163 def declare(&block) instance_eval(&block) if block_given? self end
Source
# File lib/cfndsl/jsonable.rb, line 127 def external_parameters self.class.external_parameters end
Source
# File lib/cfndsl/jsonable.rb, line 159 def ref_children instance_variables.map { |var| instance_variable_get(var) } end
Source
# File lib/cfndsl/jsonable.rb, line 155 def to_json(*args) as_json.to_json(*args) end
Private Instance Methods
Source
# File lib/cfndsl/jsonable.rb, line 170 def check_names return if instance_variable_get('@Resources').nil? instance_variable_get('@Resources').each_key do |name| next unless name !~ /\A\p{Alnum}+\z/ warn "Resource name: #{name} is invalid" exit 1 end end