class BetterErrors::Editor
Constants
- KNOWN_EDITORS
Attributes
url_proc[R]
Public Class Methods
default_editor()
click to toggle source
Automatically sniffs a default editor preset based on environment variables.
@return [Symbol]
# File lib/better_errors/editor.rb, line 31 def self.default_editor editor_from_environment_formatting_string || editor_from_environment_editor || editor_from_symbol(:textmate) end
editor_from_command(editor_command)
click to toggle source
# File lib/better_errors/editor.rb, line 52 def self.editor_from_command(editor_command) env_preset = KNOWN_EDITORS.find { |preset| editor_command =~ preset[:sniff] } for_formatting_string(env_preset[:url]) if env_preset end
editor_from_environment_editor()
click to toggle source
# File lib/better_errors/editor.rb, line 37 def self.editor_from_environment_editor if ENV["BETTER_ERRORS_EDITOR"] editor = editor_from_command(ENV["BETTER_ERRORS_EDITOR"]) return editor if editor puts "BETTER_ERRORS_EDITOR environment variable is not recognized as a supported Better Errors editor." end if ENV["EDITOR"] editor = editor_from_command(ENV["EDITOR"]) return editor if editor puts "EDITOR environment variable is not recognized as a supported Better Errors editor. Using TextMate by default." else puts "Since there is no EDITOR or BETTER_ERRORS_EDITOR environment variable, using Textmate by default." end end
editor_from_environment_formatting_string()
click to toggle source
# File lib/better_errors/editor.rb, line 57 def self.editor_from_environment_formatting_string return unless ENV['BETTER_ERRORS_EDITOR_URL'] for_formatting_string(ENV['BETTER_ERRORS_EDITOR_URL']) end
editor_from_symbol(symbol)
click to toggle source
# File lib/better_errors/editor.rb, line 63 def self.editor_from_symbol(symbol) KNOWN_EDITORS.each do |preset| return for_formatting_string(preset[:url]) if preset[:symbols].include?(symbol) end end
for_formatting_string(formatting_string)
click to toggle source
# File lib/better_errors/editor.rb, line 17 def self.for_formatting_string(formatting_string) new proc { |file, line| formatting_string % { file: URI.encode_www_form_component(file), file_unencoded: file, line: line } } end
for_proc(url_proc)
click to toggle source
# File lib/better_errors/editor.rb, line 23 def self.for_proc(url_proc) new url_proc end
new(url_proc)
click to toggle source
# File lib/better_errors/editor.rb, line 69 def initialize(url_proc) @url_proc = url_proc end
Public Instance Methods
scheme()
click to toggle source
# File lib/better_errors/editor.rb, line 87 def scheme url('/fake', 42).sub(/:.*/, ':') end
url(raw_path, line)
click to toggle source
# File lib/better_errors/editor.rb, line 73 def url(raw_path, line) if virtual_path && raw_path.start_with?(virtual_path) if host_path file = raw_path.sub(%r{\A#{virtual_path}}, host_path) else file = raw_path.sub(%r{\A#{virtual_path}/}, '') end else file = raw_path end url_proc.call(file, line) end
Private Instance Methods
host_path()
click to toggle source
# File lib/better_errors/editor.rb, line 99 def host_path @host_path ||= ENV['BETTER_ERRORS_HOST_PATH'] end
virtual_path()
click to toggle source
# File lib/better_errors/editor.rb, line 95 def virtual_path @virtual_path ||= ENV['BETTER_ERRORS_VIRTUAL_PATH'] end