Method: BetterErrors.editor=

Defined in:
lib/better_errors.rb

.BetterErrors.editor=(sym) ⇒ Object .BetterErrors.editor=(str) ⇒ Object .BetterErrors.editor=(proc) ⇒ Object

Configures how Better Errors generates open-in-editor URLs.

Overloads:

  • .BetterErrors.editor=(sym) ⇒ Object

    Uses one of the preset editor configurations. Valid symbols are:

    • :textmate, :txmt, :tm
    • :sublime, :subl, :st
    • :macvim
    • :atom

    Parameters:

    • sym (Symbol)
  • .BetterErrors.editor=(str) ⇒ Object

    Uses str as the format string for generating open-in-editor URLs.

    Use %{file} and %{line} as placeholders for the actual values.

    Examples:

    BetterErrors.editor = "my-editor://open?url=%{file}&line=%{line}"

    Parameters:

    • str (String)
  • .BetterErrors.editor=(proc) ⇒ Object

    Uses proc to generate open-in-editor URLs. The proc will be called with file and line parameters when a URL needs to be generated.

    Your proc should take care to escape file appropriately with URI.encode_www_form_component (please note that URI.escape is not a suitable substitute.)

    Examples:

    BetterErrors.editor = proc { |file, line|
      "my-editor://open?url=#{URI.encode_www_form_component file}&line=#{line}"
    }

    Parameters:

    • proc (Proc)

106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/better_errors.rb', line 106

def self.editor=(editor)
  if editor.is_a? Symbol
    @editor = Editor.editor_from_symbol(editor)
    raise(ArgumentError, "Symbol #{editor} is not a symbol in the list of supported errors.") unless editor
  elsif editor.is_a? String
    @editor = Editor.for_formatting_string(editor)
  elsif editor.respond_to? :call
    @editor = Editor.for_proc(editor)
  else
    raise ArgumentError, "Expected editor to be a valid editor key, a format string or a callable."
  end
end