class BetterSJR::TryCatchStatement

Wraps a given code snippet in a JavaScript try-catch statement

Attributes

original_code[RW]

@return [String] the code without a try-catch statement surrounding it

Public Class Methods

new(code) click to toggle source

Returns a new instance of TryCatchStatement

@param code [String] the code to be surrounded by a try-catch statement

# File lib/better_sjr/try_catch_statement.rb, line 10
def initialize(code)
  @original_code = code
end

Public Instance Methods

wrapped_code() click to toggle source

Wraps the original code in a try-catch statement

@return [String] the try-catch statement

# File lib/better_sjr/try_catch_statement.rb, line 17
    def wrapped_code
      <<-TRYCATCH
        try {
          #{original_code}
        } catch(e) {
          console.error("Rails SJR error", e);
        }
      TRYCATCH
    end