hyper-pure-rb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/better_errors-2.10.1/CHANGELOG.md +3 -0
  3. data/better_errors-2.10.1/Gemfile +11 -0
  4. data/better_errors-2.10.1/LICENSE +22 -0
  5. data/better_errors-2.10.1/README.md +163 -0
  6. data/better_errors-2.10.1/better_errors.gemspec +48 -0
  7. data/better_errors-2.10.1/gemfiles/pry010.gemfile +10 -0
  8. data/better_errors-2.10.1/gemfiles/pry011.gemfile +9 -0
  9. data/better_errors-2.10.1/gemfiles/pry09.gemfile +9 -0
  10. data/better_errors-2.10.1/gemfiles/rack.gemfile +8 -0
  11. data/better_errors-2.10.1/gemfiles/rack_boc.gemfile +9 -0
  12. data/better_errors-2.10.1/gemfiles/rails42.gemfile +10 -0
  13. data/better_errors-2.10.1/gemfiles/rails42_boc.gemfile +11 -0
  14. data/better_errors-2.10.1/gemfiles/rails42_haml.gemfile +11 -0
  15. data/better_errors-2.10.1/gemfiles/rails50.gemfile +9 -0
  16. data/better_errors-2.10.1/gemfiles/rails50_boc.gemfile +10 -0
  17. data/better_errors-2.10.1/gemfiles/rails50_haml.gemfile +10 -0
  18. data/better_errors-2.10.1/gemfiles/rails51.gemfile +9 -0
  19. data/better_errors-2.10.1/gemfiles/rails51_boc.gemfile +10 -0
  20. data/better_errors-2.10.1/gemfiles/rails51_haml.gemfile +10 -0
  21. data/better_errors-2.10.1/gemfiles/rails52.gemfile +9 -0
  22. data/better_errors-2.10.1/gemfiles/rails52_boc.gemfile +10 -0
  23. data/better_errors-2.10.1/gemfiles/rails52_haml.gemfile +10 -0
  24. data/better_errors-2.10.1/gemfiles/rails60.gemfile +8 -0
  25. data/better_errors-2.10.1/gemfiles/rails60_boc.gemfile +9 -0
  26. data/better_errors-2.10.1/gemfiles/rails60_haml.gemfile +9 -0
  27. data/better_errors-2.10.1/gemfiles/rails61.gemfile +8 -0
  28. data/better_errors-2.10.1/gemfiles/rails61_boc.gemfile +9 -0
  29. data/better_errors-2.10.1/gemfiles/rails61_haml.gemfile +9 -0
  30. data/better_errors-2.10.1/lib/better_errors/code_formatter/html.rb +40 -0
  31. data/better_errors-2.10.1/lib/better_errors/code_formatter/text.rb +14 -0
  32. data/better_errors-2.10.1/lib/better_errors/code_formatter.rb +52 -0
  33. data/better_errors-2.10.1/lib/better_errors/editor.rb +103 -0
  34. data/better_errors-2.10.1/lib/better_errors/error_page.rb +169 -0
  35. data/better_errors-2.10.1/lib/better_errors/error_page_style.rb +43 -0
  36. data/better_errors-2.10.1/lib/better_errors/exception_extension.rb +17 -0
  37. data/better_errors-2.10.1/lib/better_errors/exception_hint.rb +29 -0
  38. data/better_errors-2.10.1/lib/better_errors/inspectable_value.rb +45 -0
  39. data/better_errors-2.10.1/lib/better_errors/middleware.rb +237 -0
  40. data/better_errors-2.10.1/lib/better_errors/rails.rb +28 -0
  41. data/better_errors-2.10.1/lib/better_errors/raised_exception.rb +89 -0
  42. data/better_errors-2.10.1/lib/better_errors/repl/basic.rb +20 -0
  43. data/better_errors-2.10.1/lib/better_errors/repl/pry.rb +88 -0
  44. data/better_errors-2.10.1/lib/better_errors/repl.rb +32 -0
  45. data/better_errors-2.10.1/lib/better_errors/stack_frame.rb +136 -0
  46. data/better_errors-2.10.1/lib/better_errors/templates/main.css +1 -0
  47. data/better_errors-2.10.1/lib/better_errors/templates/main.erb +431 -0
  48. data/better_errors-2.10.1/lib/better_errors/templates/text.erb +24 -0
  49. data/better_errors-2.10.1/lib/better_errors/templates/variable_info.erb +82 -0
  50. data/better_errors-2.10.1/lib/better_errors/version.rb +4 -0
  51. data/better_errors-2.10.1/lib/better_errors.rb +144 -0
  52. data/hyper-pure-rb.gemspec +11 -0
  53. metadata +91 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9164f3c2d2b90e5d3ee206e49dd459ca88ad86fad76680cac16c5697218843f9
4
+ data.tar.gz: c00d168bd48713fa562b4418d3d77e3f6a7ea720a1784fb3b2dc4e614008e965
5
+ SHA512:
6
+ metadata.gz: 43ae5013f78d278ec2698e8833c99e4ff4714921d13f973b8142563992f512232b62bb5a30a234e1ced69c7529ef6b505f4ebfc6395abf42dd6540215fa530c6
7
+ data.tar.gz: c4de1df75e289b38fc5c915693b69c9a791a9631f2a2d75ccd9f52ea4329f97f7e3ee53ed3c20a4db2e14d865b433fbdec0a1102c411aaafab12b823dbd26cbf
@@ -0,0 +1,3 @@
1
+ # Changelog
2
+
3
+ See https://github.com/BetterErrors/better_errors/releases
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'simplecov', require: false
6
+ gem 'simplecov-lcov', require: false
7
+
8
+ # For managing release version in CI
9
+ gem 'gem-release'
10
+
11
+ # gem "pry-byebug"
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012-2023 Hailey Somerville
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,163 @@
1
+ [![Build Status](https://github.com/BetterErrors/better_errors/workflows/CI/badge.svg?event=push&branch=master)](https://github.com/BetterErrors/better_errors/actions?query=branch%3Amaster)
2
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6bc3e7d6118d47e6959b16690b815909)](https://www.codacy.com/app/BetterErrors/better_errors?utm_source=github.com&utm_medium=referral&utm_content=BetterErrors/better_errors&utm_campaign=Badge_Grade)
3
+ [![Test Coverage](https://coveralls.io/repos/github/BetterErrors/better_errors/badge.svg?branch=master)](https://coveralls.io/github/BetterErrors/better_errors?branch=master)
4
+ [![Gem Version](https://img.shields.io/gem/v/better_errors.svg)](https://rubygems.org/gems/better_errors)
5
+
6
+ # Better Errors
7
+
8
+ Better Errors replaces the standard Rails error page with a much better and more useful error page. It is also usable outside of Rails in any Rack app as Rack middleware.
9
+
10
+ ![screenshot of Better Errors in action](https://i.imgur.com/6zBGAAb.png)
11
+
12
+ ## Features
13
+
14
+ For screenshots of these features, [see the wiki](https://github.com/BetterErrors/better_errors/wiki).
15
+
16
+ * Full stack trace
17
+ * Source code inspection for all stack frames (with highlighting)
18
+ * Local and instance variable inspection
19
+ * Live shell (REPL) on every stack frame
20
+ * Links directly to the source line in your editor
21
+ * Useful information in non-HTML requests
22
+
23
+ ## Installation
24
+
25
+ Add this to your Gemfile:
26
+
27
+ ```ruby
28
+ group :development do
29
+ gem "better_errors"
30
+ gem "binding_of_caller"
31
+ end
32
+ ```
33
+
34
+ [`binding_of_caller`](https://github.com/banister/binding_of_caller) is optional, but is necessary to use Better Errors' advanced features (REPL, local/instance variable inspection, pretty stack frame names).
35
+
36
+ _Note: If you discover that Better Errors isn't working - particularly after upgrading from version 0.5.0 or less - be sure to set `config.consider_all_requests_local = true` in `config/environments/development.rb`._
37
+
38
+ ### Optional: Set `EDITOR`
39
+
40
+ For many reasons outside of Better Errors, you should have the `EDITOR` environment variable set to your preferred
41
+ editor.
42
+ Better Errors, like many other tools, will use that environment variable to show a link that opens your
43
+ editor to the file and line from the console.
44
+
45
+ By default the links will open TextMate-protocol links.
46
+
47
+ To see if your editor is supported or to set up a different editor, see [the wiki](https://github.com/BetterErrors/better_errors/wiki/Link-to-your-editor).
48
+
49
+ ### Optional: Set `BETTER_ERRORS_INSIDE_FRAME`
50
+
51
+ If your application is running inside of an iframe, or if you have a Content Security Policy that disallows links
52
+ to other protocols, the editor links will not work.
53
+
54
+ To work around this set `BETTER_ERRORS_INSIDE_FRAME=1` in the environment, and the links will include `target=_blank`,
55
+ allowing the link to open regardless of the policy.
56
+
57
+ _This works because it opens the editor from a new browser tab, escaping from the restrictions of your site._
58
+ _Unfortunately it leaves behind an empty tab each time, so only use this if needed._
59
+
60
+ ## Security
61
+
62
+ **NOTE:** It is *critical* you put better\_errors only in the **development** section of your Gemfile.
63
+ **Do NOT run better_errors in production, or on Internet-facing hosts.**
64
+
65
+ You will notice that the only machine that gets the Better Errors page is localhost, which means you get the default error page if you are developing on a remote host (or a virtually remote host, such as a Vagrant box).
66
+ Obviously, the REPL is not something you want to expose to the public, and there may be sensitive information available in the backtrace.
67
+
68
+ For more information on how to configure access, see [the wiki](https://github.com/BetterErrors/better_errors/wiki/Allowing-access-to-the-console).
69
+
70
+ ## Usage
71
+
72
+ If you're using Rails, there's nothing else you need to do.
73
+
74
+ ### Using without Rails.
75
+
76
+ If you're not using Rails, you need to insert `BetterErrors::Middleware` into your middleware stack, and optionally set `BetterErrors.application_root` if you'd like Better Errors to abbreviate filenames within your application.
77
+
78
+ For instructions for your specific middleware, [see the wiki](https://github.com/BetterErrors/better_errors/wiki/Non-Rails-frameworks).
79
+
80
+ ### Plain text requests
81
+
82
+ Better Errors will render a plain text error page when the request is an
83
+ `XMLHttpRequest` or when the `Accept` header does *not* include 'html'.
84
+
85
+ ### Unicorn, Puma, and other multi-worker servers
86
+
87
+ Better Errors works by leaving a lot of context in server process memory.
88
+ If you're using a web server that runs multiple "workers" it's likely that a second
89
+ request (as happens when you click on a stack frame) will hit a different
90
+ worker.
91
+ That worker won't have the necessary context in memory, and you'll see
92
+ a `Session Expired` message.
93
+
94
+ If this is the case for you, consider turning the number of workers to one (1)
95
+ in `development`. Another option would be to use Webrick, Mongrel, Thin,
96
+ or another single-process server as your `rails server`, when you are trying
97
+ to troubleshoot an issue in development.
98
+
99
+ ### Changing the link to your editor
100
+
101
+ Better Errors includes a link to your editor for the file and line of code that is being shown.
102
+ By default, it uses your environment to determine which editor should be opened.
103
+ See [the wiki for instructions on configuring the editor](https://github.com/BetterErrors/better_errors/wiki/Link-to-your-editor).
104
+
105
+
106
+ ## Set maximum variable size for inspector.
107
+
108
+ ```ruby
109
+ # e.g. in config/initializers/better_errors.rb
110
+ # This will stop BetterErrors from trying to render larger objects, which can cause
111
+ # slow loading times and browser performance problems. Stated size is in characters and refers
112
+ # to the length of #inspect's payload for the given object. Please be aware that HTML escaping
113
+ # modifies the size of this payload so setting this limit too precisely is not recommended.
114
+ # default value: 100_000
115
+ BetterErrors.maximum_variable_inspect_size = 100_000
116
+ ```
117
+
118
+ ## Ignore inspection of variables with certain classes.
119
+
120
+ ```ruby
121
+ # e.g. in config/initializers/better_errors.rb
122
+ # This will stop BetterErrors from trying to inspect objects of these classes, which can cause
123
+ # slow loading times and unnecessary database queries. Does not check inheritance chain, use
124
+ # strings not constants.
125
+ # default value: ['ActionDispatch::Request', 'ActionDispatch::Response']
126
+ BetterErrors.ignored_classes = ['ActionDispatch::Request', 'ActionDispatch::Response']
127
+ ```
128
+
129
+ ## Get in touch!
130
+
131
+ If you're using better_errors, I'd love to hear from you. Drop me a line and tell me what you think!
132
+
133
+ ## Development
134
+
135
+ After checking out the repo, run `bundle install` to install the basic dependencies.
136
+
137
+ You can run the tests with the simplest set of dependencies using:
138
+
139
+ ```rb
140
+ bundle exec rspec
141
+ ```
142
+
143
+ To run specs for each of the dependency combinations, run:
144
+
145
+ ```rb
146
+ bundle exec rake test:all
147
+ ```
148
+
149
+ You can run specs for a specific dependency combination using:
150
+
151
+ ```rb
152
+ BUNDLE_GEMFILE=gemfiles/pry09.gemfile bundle exec rspec
153
+ ```
154
+
155
+ On CI, the specs are run against each gemfile on each supported version of Ruby.
156
+
157
+ ## Contributing
158
+
159
+ 1. Fork it
160
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
161
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
162
+ 4. Push to the branch (`git push origin my-new-feature`)
163
+ 5. Create new Pull Request
@@ -0,0 +1,48 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'better_errors/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "better_errors"
7
+ s.version = BetterErrors::VERSION
8
+ s.authors = ["Hailey Somerville"]
9
+ s.email = ["hailey@hailey.lol"]
10
+ s.description = %q{Provides a better error page for Rails and other Rack apps. Includes source code inspection, a live REPL and local/instance variable inspection for all stack frames.}
11
+ s.summary = %q{Better error page for Rails and other Rack apps}
12
+ s.homepage = "https://github.com/BetterErrors/better_errors"
13
+ s.license = "MIT"
14
+
15
+ s.files = `git ls-files -z`.split("\x0").reject { |f|
16
+ f.match(%r{^((test|spec|features|feature-screenshots)/|Rakefile)|\.scss$})
17
+ } + %w[lib/better_errors/templates/main.css]
18
+
19
+ s.require_paths = ["lib"]
20
+
21
+ s.required_ruby_version = ">= 2.0.0"
22
+
23
+ s.add_development_dependency "rake", "~> 10.0"
24
+ s.add_development_dependency "rspec", "~> 3.5"
25
+ s.add_development_dependency "rspec-html-matchers"
26
+ s.add_development_dependency "rspec-its"
27
+ s.add_development_dependency "yard"
28
+ s.add_development_dependency "sassc"
29
+ # kramdown 2.1 requires Ruby 2.3+
30
+ s.add_development_dependency "kramdown", (RUBY_VERSION < '2.3' ? '< 2.0.0' : '> 2.0.0')
31
+ # simplecov and coveralls must not be included here. See the Gemfiles instead.
32
+
33
+ s.add_dependency "erubi", ">= 1.0.0"
34
+ s.add_dependency "rouge", ">= 1.0.0"
35
+ s.add_dependency "rack", ">= 0.9.0"
36
+
37
+ # optional dependencies:
38
+ # s.add_dependency "binding_of_caller"
39
+ # s.add_dependency "pry"
40
+
41
+ if s.respond_to?(:metadata)
42
+ s.metadata['changelog_uri'] = 'https://github.com/BetterErrors/better_errors/releases'
43
+ s.metadata['source_code_uri'] = 'https://github.com/BetterErrors/better_errors'
44
+ s.metadata['bug_tracker_uri'] = 'https://github.com/BetterErrors/better_errors/issues'
45
+ else
46
+ puts "Your RubyGems does not support metadata. Update if you'd like to make a release."
47
+ end
48
+ end
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rack', RUBY_VERSION < '2.2.2' ? '~> 1.6' : '~> 2.0'
4
+ gem "binding_of_caller"
5
+ gem "pry", "~> 0.10.0"
6
+
7
+ gem 'simplecov', require: false
8
+ gem 'simplecov-lcov', require: false
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rack', RUBY_VERSION < '2.2.2' ? '~> 1.6' : '~> 2.0'
4
+ gem "pry", "~> 0.11.0pre"
5
+
6
+ gem 'simplecov', require: false
7
+ gem 'simplecov-lcov', require: false
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rack', RUBY_VERSION < '2.2.2' ? '~> 1.6' : '~> 2.0'
4
+ gem "pry", "~> 0.9.12"
5
+
6
+ gem 'simplecov', require: false
7
+ gem 'simplecov-lcov', require: false
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rack', RUBY_VERSION < '2.2.2' ? '~> 1.6' : '~> 2.0'
4
+
5
+ gem 'simplecov', require: false
6
+ gem 'simplecov-lcov', require: false
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rack', RUBY_VERSION < '2.2.2' ? '~> 1.6' : '~> 2.0'
4
+ gem "binding_of_caller"
5
+
6
+ gem 'simplecov', require: false
7
+ gem 'simplecov-lcov', require: false
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 4.2.0"
4
+ gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
5
+ gem 'i18n', '< 1.5.2' if RUBY_VERSION < '2.3'
6
+
7
+ gem 'simplecov', require: false
8
+ gem 'simplecov-lcov', require: false
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 4.2.0"
4
+ gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
5
+ gem 'i18n', '< 1.5.2' if RUBY_VERSION < '2.3'
6
+ gem "binding_of_caller"
7
+
8
+ gem 'simplecov', require: false
9
+ gem 'simplecov-lcov', require: false
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 4.2.0"
4
+ gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
5
+ gem 'i18n', '< 1.5.2' if RUBY_VERSION < '2.3'
6
+ gem "haml"
7
+
8
+ gem 'simplecov', require: false
9
+ gem 'simplecov-lcov', require: false
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 5.0.0"
4
+ gem 'i18n', '< 1.5.2' if RUBY_VERSION < '2.3'
5
+
6
+ gem 'simplecov', require: false
7
+ gem 'simplecov-lcov', require: false
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 5.0.0"
4
+ gem 'i18n', '< 1.5.2' if RUBY_VERSION < '2.3'
5
+ gem "binding_of_caller"
6
+
7
+ gem 'simplecov', require: false
8
+ gem 'simplecov-lcov', require: false
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 5.0.0"
4
+ gem 'i18n', '< 1.5.2' if RUBY_VERSION < '2.3'
5
+ gem "haml"
6
+
7
+ gem 'simplecov', require: false
8
+ gem 'simplecov-lcov', require: false
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 5.1.0"
4
+ gem 'i18n', '< 1.5.2', require: false if RUBY_VERSION < '2.3'
5
+
6
+ gem 'simplecov', require: false
7
+ gem 'simplecov-lcov', require: false
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 5.1.0"
4
+ gem 'i18n', '< 1.5.2' if RUBY_VERSION < '2.3'
5
+ gem "binding_of_caller"
6
+
7
+ gem 'simplecov', require: false
8
+ gem 'simplecov-lcov', require: false
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 5.1.0"
4
+ gem 'i18n', '< 1.5.2' if RUBY_VERSION < '2.3'
5
+ gem "haml"
6
+
7
+ gem 'simplecov', require: false
8
+ gem 'simplecov-lcov', require: false
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 5.2.0"
4
+ gem 'i18n', '< 1.5.2' if RUBY_VERSION < '2.3'
5
+
6
+ gem 'simplecov', require: false
7
+ gem 'simplecov-lcov', require: false
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 5.2.0"
4
+ gem 'i18n', '< 1.5.2' if RUBY_VERSION < '2.3'
5
+ gem "binding_of_caller"
6
+
7
+ gem 'simplecov', require: false
8
+ gem 'simplecov-lcov', require: false
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 5.2.0"
4
+ gem 'i18n', '< 1.5.2' if RUBY_VERSION < '2.3'
5
+ gem "haml"
6
+
7
+ gem 'simplecov', require: false
8
+ gem 'simplecov-lcov', require: false
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 6.0.0"
4
+
5
+ gem 'simplecov', require: false
6
+ gem 'simplecov-lcov', require: false
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 6.0.0"
4
+ gem "binding_of_caller"
5
+
6
+ gem 'simplecov', require: false
7
+ gem 'simplecov-lcov', require: false
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 6.0.0"
4
+ gem "haml"
5
+
6
+ gem 'simplecov', require: false
7
+ gem 'simplecov-lcov', require: false
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 6.1.0rc"
4
+
5
+ gem 'simplecov', require: false
6
+ gem 'simplecov-lcov', require: false
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 6.1.0rc"
4
+ gem "binding_of_caller"
5
+
6
+ gem 'simplecov', require: false
7
+ gem 'simplecov-lcov', require: false
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 6.1.0rc"
4
+ gem "haml"
5
+
6
+ gem 'simplecov', require: false
7
+ gem 'simplecov-lcov', require: false
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,40 @@
1
+ require "rouge"
2
+
3
+ module BetterErrors
4
+ # @private
5
+ class CodeFormatter::HTML < CodeFormatter
6
+ def source_unavailable
7
+ "<p class='unavailable'>Source is not available</p>"
8
+ end
9
+
10
+ def formatted_lines
11
+ each_line_of(highlighted_lines) { |highlight, current_line, str|
12
+ class_name = highlight ? "highlight" : ""
13
+ sprintf '<pre class="%s">%s</pre>', class_name, str
14
+ }
15
+ end
16
+
17
+ def formatted_nums
18
+ each_line_of(highlighted_lines) { |highlight, current_line, str|
19
+ class_name = highlight ? "highlight" : ""
20
+ sprintf '<span class="%s">%5d</span>', class_name, current_line
21
+ }
22
+ end
23
+
24
+ def formatted_code
25
+ %{
26
+ <div class="code_linenums">#{formatted_nums.join}</div>
27
+ <div class="code"><div class='code-wrapper'>#{super}</div></div>
28
+ }
29
+ end
30
+
31
+ def rouge_lexer
32
+ Rouge::Lexer.guess(filename: filename, source: source) { Rouge::Lexers::Ruby }
33
+ end
34
+
35
+ def highlighted_lines
36
+ Rouge::Formatters::HTML.new.format(rouge_lexer.lex(context_lines.join)).lines
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ module BetterErrors
2
+ # @private
3
+ class CodeFormatter::Text < CodeFormatter
4
+ def source_unavailable
5
+ "# Source is not available"
6
+ end
7
+
8
+ def formatted_lines
9
+ each_line_of(context_lines) { |highlight, current_line, str|
10
+ sprintf '%s %3d %s', (highlight ? '>' : ' '), current_line, str
11
+ }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,52 @@
1
+ module BetterErrors
2
+ # @private
3
+ class CodeFormatter
4
+ require "better_errors/code_formatter/html"
5
+ require "better_errors/code_formatter/text"
6
+
7
+ attr_reader :filename, :line, :context
8
+
9
+ def initialize(filename, line, context = 5)
10
+ @filename = filename
11
+ @line = line
12
+ @context = context
13
+ end
14
+
15
+ def output
16
+ formatted_code
17
+ rescue Errno::ENOENT, Errno::EINVAL
18
+ source_unavailable
19
+ end
20
+
21
+ def line_range
22
+ min = [line - context, 1].max
23
+ max = [line + context, source_lines.count].min
24
+ min..max
25
+ end
26
+
27
+ def context_lines
28
+ range = line_range
29
+ source_lines[(range.begin - 1)..(range.end - 1)] or raise Errno::EINVAL
30
+ end
31
+
32
+ private
33
+
34
+ def formatted_code
35
+ formatted_lines.join
36
+ end
37
+
38
+ def each_line_of(lines, &blk)
39
+ line_range.zip(lines).map { |current_line, str|
40
+ yield (current_line == line), current_line, str
41
+ }
42
+ end
43
+
44
+ def source
45
+ @source ||= File.read(filename)
46
+ end
47
+
48
+ def source_lines
49
+ @source_lines ||= source.lines
50
+ end
51
+ end
52
+ end