Class: BetterSJR::TryCatchStatement

Inherits:
Object
  • Object
show all
Defined in:
lib/better_sjr/try_catch_statement.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ TryCatchStatement

Returns a new instance of TryCatchStatement

Parameters:

  • code (String)

    the code to be surrounded by a try-catch statement



10
11
12
# File 'lib/better_sjr/try_catch_statement.rb', line 10

def initialize(code)
  @original_code = code
end

Instance Attribute Details

#original_codeString

Returns the code without a try-catch statement surrounding it.

Returns:

  • (String)

    the code without a try-catch statement surrounding it



5
6
7
# File 'lib/better_sjr/try_catch_statement.rb', line 5

def original_code
  @original_code
end

Instance Method Details

#wrapped_codeString

Wraps the original code in a try-catch statement

Returns:

  • (String)

    the try-catch statement



17
18
19
20
21
22
23
24
25
# 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