Module: BetterErrors
- Defined in:
- lib/better_errors.rb,
lib/better_errors/repl.rb,
lib/better_errors/rails.rb,
lib/better_errors/version.rb,
lib/better_errors/repl/pry.rb,
lib/better_errors/error_page.rb,
lib/better_errors/middleware.rb,
lib/better_errors/repl/basic.rb,
lib/better_errors/stack_frame.rb,
lib/better_errors/code_formatter.rb,
lib/better_errors/code_formatter/html.rb,
lib/better_errors/code_formatter/text.rb
Defined Under Namespace
Classes: Middleware
Constant Summary collapse
- POSSIBLE_EDITOR_PRESETS =
[ { symbols: [:emacs, :emacsclient], sniff: /emacs/i, url: "emacs://open?url=file://%{file}&line=%{line}" }, { symbols: [:macvim, :mvim], sniff: /vim/i, url: proc { |file, line| "mvim://open?url=file://#{file}&line=#{line}" } }, { symbols: [:sublime, :subl, :st], sniff: /subl/i, url: "subl://open?url=file://%{file}&line=%{line}" }, { symbols: [:textmate, :txmt, :tm], sniff: /mate/i, url: "txmt://open?url=file://%{file}&line=%{line}" }, ]
- VERSION =
"1.1.0"
Class Attribute Summary collapse
-
.application_root ⇒ String
The path to the root of the application.
-
.ignored_instance_variables ⇒ Array
The ignored instance variables.
-
.logger ⇒ Logger?
The logger to use when logging exception details and backtraces.
Class Method Summary collapse
-
.default_editor ⇒ Symbol
Automatically sniffs a default editor preset based on the EDITOR environment variable.
-
.editor ⇒ Proc
Returns a proc, which when called with a filename and line number argument, returns a URL to open the filename and line in the selected editor.
-
.editor=(editor) ⇒ Object
Configures how Better Errors generates open-in-editor URLs.
-
.use_pry! ⇒ Object
Enables experimental Pry support in the inline REPL.
Class Attribute Details
.application_root ⇒ String
The path to the root of the application. Better Errors uses this property to determine if a file in a backtrace should be considered an application frame. If you are using Better Errors with Rails, you do not need to set this attribute manually.
28 29 30 |
# File 'lib/better_errors.rb', line 28 def application_root @application_root end |
.ignored_instance_variables ⇒ Array
The ignored instance variables.
45 46 47 |
# File 'lib/better_errors.rb', line 45 def ignored_instance_variables @ignored_instance_variables end |
.logger ⇒ Logger?
The logger to use when logging exception details and backtraces. If you
are using Better Errors with Rails, you do not need to set this attribute
manually. If this attribute is nil
, nothing will be logged.
35 36 37 |
# File 'lib/better_errors.rb', line 35 def logger @logger end |
Class Method Details
.default_editor ⇒ Symbol
Automatically sniffs a default editor preset based on the EDITOR environment variable.
128 129 130 131 132 |
# File 'lib/better_errors.rb', line 128 def self.default_editor POSSIBLE_EDITOR_PRESETS.detect(-> { {} }) { |config| ENV["EDITOR"] =~ config[:sniff] }[:url] || :textmate end |
.editor ⇒ Proc
Returns a proc, which when called with a filename and line number argument, returns a URL to open the filename and line in the selected editor.
Generates TextMate URLs by default.
BetterErrors.editor["/some/file", 123] # => txmt://open?url=file:///some/file&line=123
58 59 60 |
# File 'lib/better_errors.rb', line 58 def self.editor @editor end |
.BetterErrors.editor=(sym) ⇒ Object .BetterErrors.editor=(str) ⇒ Object .BetterErrors.editor=(proc) ⇒ Object
Configures how Better Errors generates open-in-editor URLs.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/better_errors.rb', line 98 def self.editor=(editor) POSSIBLE_EDITOR_PRESETS.each do |config| if config[:symbols].include?(editor) return self.editor = config[:url] end end if editor.is_a? String self.editor = proc { |file, line| editor % { file: URI.encode_www_form_component(file), line: line } } else if editor.respond_to? :call @editor = editor else raise TypeError, "Expected editor to be a valid editor key, a format string or a callable." end end end |
.use_pry! ⇒ Object
Enables experimental Pry support in the inline REPL
If you encounter problems while using Pry, please file a bug report at https://github.com/charliesome/better_errors/issues
120 121 122 |
# File 'lib/better_errors.rb', line 120 def self.use_pry! REPL::PROVIDERS.unshift const: :Pry, impl: "better_errors/repl/pry" end |