lib/cfndsl/JSONable.rb in cfndsl-0.1.11 vs lib/cfndsl/JSONable.rb in cfndsl-0.1.12

- old
+ new

@@ -174,17 +174,26 @@ def declare(&block) self.instance_eval &block if block_given? end - def method_missing(meth,*args,&block) - if(args) then - arg = "(" + args.inspect[1..-2] + ")" - else - arg = "" - end - CfnDsl::Errors.error( "Undefined symbol: #{meth}#{arg}", 1 ) + 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 + + def incorrect_capitalization?(method) + method != titleize(method) && respond_to?(titleize(method)) + end + + def titleize(method) + method.to_s.clone.tap do |m| + m[0] = m[0,1].upcase + end.to_sym + end + end class Fn < JSONable ##