Class: CfnDsl::JSONable
Direct Known Subclasses
AWSTypes::AWSType, ConditionDefinition, CreationPolicyDefinition, Fn, MappingDefinition, MetadataDefinition, OSTypes::OSType, OrchestrationTemplate, OutputDefinition, ParameterDefinition, PropertyDefinition, RefDefinition, ResourceDefinition, UpdatePolicyDefinition
Instance Method Summary
collapse
Methods included from Functions
FnAnd, FnBase64, FnEquals, FnFindInMap, FnFormat, FnGetAZs, FnGetAtt, FnIf, FnJoin, FnNot, FnOr, FnSelect, Ref
Methods included from RefCheck
#references
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
179
180
181
182
183
184
|
# File 'lib/cfndsl/JSONable.rb', line 179
def method_missing(meth, *args, &block)
error = "Undefined symbol: #{meth}"
error = "#{error}(" + args.inspect[1..-2] + ")" unless args.empty?
error = "#{error}\n\nTry '#{titleize(meth)}' instead" if incorrect_capitalization?(meth)
CfnDsl::Errors.error(error, 1)
end
|
Instance Method Details
#declare(&block) ⇒ Object
175
176
177
|
# File 'lib/cfndsl/JSONable.rb', line 175
def declare(&block)
self.instance_eval &block if block_given?
end
|
#incorrect_capitalization?(method) ⇒ Boolean
186
187
188
|
# File 'lib/cfndsl/JSONable.rb', line 186
def incorrect_capitalization?(method)
method != titleize(method) && respond_to?(titleize(method))
end
|
#ref_children ⇒ Object
171
172
173
|
# File 'lib/cfndsl/JSONable.rb', line 171
def ref_children
return self.instance_variables.map { |var| self.instance_variable_get var }
end
|
#titleize(method) ⇒ Object
190
191
192
193
194
|
# File 'lib/cfndsl/JSONable.rb', line 190
def titleize(method)
method.to_s.clone.tap do |m|
m[0] = m[0,1].upcase
end.to_sym
end
|
#to_json(*a) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/cfndsl/JSONable.rb', line 148
def to_json(*a)
hash = {}
self.instance_variables.each do |var|
name = var[1..-1]
if( name =~ /^__/ ) then
name = name[1..-1]
elsif( name =~ /^_/ ) then
name = nil
end
hash[name] = self.instance_variable_get var if name
end
hash.to_json(*a)
end
|