backtrace_cleaner 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 83eea65eb3f67a84cbfbf598a853b2337f0ad1fb126c6cc32916abc5244a5f5d
4
+ data.tar.gz: f9fd9d74d8bf53f51588ab96474b20f2392750916ca941b299c8bee6877b2b68
5
+ SHA512:
6
+ metadata.gz: a21adffb2a8bca6d93ebd7ee66bd460c7b738d1b25a1a5aa2f2bb8b10ddb77ac8034be63a346638e4bccdf724c69184b41a8617e6fc1a9b68f767cc804754bf2
7
+ data.tar.gz: 68b9aea5cb38fcb747454537d1a95806baadacb34e23a1a102fd0def05d02859fcc5ef44e302b1f7f41e0e35f38c1813f209e2fa171dbc6a6f50064421ab193d
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at igor@morozov.is. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in backtrace_cleaner.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ backtrace_cleaner (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ backtrace_cleaner!
30
+ bundler (~> 1.17)
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Igor S. Morozov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2005-2019 David Heinemeier Hansson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # BacktraceCleaner
2
+
3
+ This is an extraction of ActiveSupport's [BacktraceCleaner](https://api.rubyonrails.org/classes/ActiveSupport/BacktraceCleaner.html) library.
4
+
5
+ This gem exists for everyone who needs this ActiveSupport's feature without the rest of ActiveSupport.
6
+
7
+ You can find original [source code](https://github.com/rails/rails/blob/dd8d37881c936d22acbc244e7e3b9b3a26e441b8/activesupport/lib/active_support/backtrace_cleaner.rb) on GitHub.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'backtrace_cleaner'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install backtrace_cleaner
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ bc = BacktraceCleaner.new
29
+ bc.add_filter { |line| line.gsub(Rails.root.to_s, '') } # strip the Rails.root prefix
30
+ bc.add_silencer { |line| line =~ /puma|rubygems/ } # skip any lines from puma or rubygems
31
+ bc.clean(exception.backtrace) # perform the cleanup
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Morozzzko/backtrace_cleaner. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
47
+
48
+ ## Code of Conduct
49
+
50
+ Everyone interacting in the BacktraceCleaner project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/backtrace_cleaner/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'backtrace_cleaner/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'backtrace_cleaner'
7
+ spec.version = BacktraceCleaner::VERSION
8
+ spec.authors = ['Igor S. Morozov']
9
+ spec.email = ['igor@morozov.is']
10
+
11
+ spec.summary = 'BacktraceCleaner from ActiveSupport without any ActiveSupport'
12
+ spec.homepage = 'https://github.com/Morozzzko'
13
+ spec.license = 'MIT'
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.17'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "backtrace_cleaner"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class BacktraceCleaner
4
+ VERSION = '1.0.0'.freeze
5
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "backtrace_cleaner/version"
4
+
5
+ # This is an extract from ActiveSupport's backtrace_cleaner
6
+ # See https://github.com/rails/rails/blob/dd8d37881c936d22acbc244e7e3b9b3a26e441b8/activesupport/lib/active_support/backtrace_cleaner.rb
7
+ #
8
+ # see LICENSE_ACTIVE_SUPPORT for the proper license
9
+
10
+ # Backtraces often include many lines that are not relevant for the context
11
+ # under review. This makes it hard to find the signal amongst the backtrace
12
+ # noise, and adds debugging time. With a BacktraceCleaner, filters and
13
+ # silencers are used to remove the noisy lines, so that only the most relevant
14
+ # lines remain.
15
+ #
16
+ # Filters are used to modify lines of data, while silencers are used to remove
17
+ # lines entirely. The typical filter use case is to remove lengthy path
18
+ # information from the start of each line, and view file paths relevant to the
19
+ # app directory instead of the file system root. The typical silencer use case
20
+ # is to exclude the output of a noisy library from the backtrace, so that you
21
+ # can focus on the rest.
22
+ #
23
+ # bc = BacktraceCleaner.new
24
+ # bc.add_filter { |line| line.gsub(Rails.root.to_s, '') } # strip the Rails.root prefix
25
+ # bc.add_silencer { |line| line =~ /puma|rubygems/ } # skip any lines from puma or rubygems
26
+ # bc.clean(exception.backtrace) # perform the cleanup
27
+ #
28
+ # To reconfigure an existing BacktraceCleaner (like the default one in Rails)
29
+ # and show as much data as possible, you can always call
30
+ # <tt>BacktraceCleaner#remove_silencers!</tt>, which will restore the
31
+ # backtrace to a pristine state. If you need to reconfigure an existing
32
+ # BacktraceCleaner so that it does not filter or modify the paths of any lines
33
+ # of the backtrace, you can call <tt>BacktraceCleaner#remove_filters!</tt>
34
+ # These two methods will give you a completely untouched backtrace.
35
+ #
36
+ # Inspired by the Quiet Backtrace gem by thoughtbot.
37
+
38
+ class BacktraceCleaner
39
+ def initialize
40
+ @filters, @silencers = [], []
41
+ add_gem_filter
42
+ add_gem_silencer
43
+ add_stdlib_silencer
44
+ end
45
+
46
+ # Returns the backtrace after all filters and silencers have been run
47
+ # against it. Filters run first, then silencers.
48
+ def clean(backtrace, kind = :silent)
49
+ filtered = filter_backtrace(backtrace)
50
+
51
+ case kind
52
+ when :silent
53
+ silence(filtered)
54
+ when :noise
55
+ noise(filtered)
56
+ else
57
+ filtered
58
+ end
59
+ end
60
+ alias :filter :clean
61
+
62
+ # Adds a filter from the block provided. Each line in the backtrace will be
63
+ # mapped against this filter.
64
+ #
65
+ # # Will turn "/my/rails/root/app/models/person.rb" into "/app/models/person.rb"
66
+ # backtrace_cleaner.add_filter { |line| line.gsub(Rails.root, '') }
67
+ def add_filter(&block)
68
+ @filters << block
69
+ end
70
+
71
+ # Adds a silencer from the block provided. If the silencer returns +true+
72
+ # for a given line, it will be excluded from the clean backtrace.
73
+ #
74
+ # # Will reject all lines that include the word "puma", like "/gems/puma/server.rb" or "/app/my_puma_server/rb"
75
+ # backtrace_cleaner.add_silencer { |line| line =~ /puma/ }
76
+ def add_silencer(&block)
77
+ @silencers << block
78
+ end
79
+
80
+ # Removes all silencers, but leaves in the filters. Useful if your
81
+ # context of debugging suddenly expands as you suspect a bug in one of
82
+ # the libraries you use.
83
+ def remove_silencers!
84
+ @silencers = []
85
+ end
86
+
87
+ # Removes all filters, but leaves in the silencers. Useful if you suddenly
88
+ # need to see entire filepaths in the backtrace that you had already
89
+ # filtered out.
90
+ def remove_filters!
91
+ @filters = []
92
+ end
93
+
94
+ private
95
+
96
+ FORMATTED_GEMS_PATTERN = /\A[^\/]+ \([\w.]+\) /
97
+
98
+ def add_gem_filter
99
+ gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
100
+ return if gems_paths.empty?
101
+
102
+ gems_regexp = %r{(#{gems_paths.join('|')})/(bundler/)?gems/([^/]+)-([\w.]+)/(.*)}
103
+ gems_result = '\3 (\4) \5'
104
+ add_filter { |line| line.sub(gems_regexp, gems_result) }
105
+ end
106
+
107
+ def add_gem_silencer
108
+ add_silencer { |line| FORMATTED_GEMS_PATTERN.match?(line) }
109
+ end
110
+
111
+ def add_stdlib_silencer
112
+ add_silencer { |line| line.start_with?(RbConfig::CONFIG["rubylibdir"]) }
113
+ end
114
+
115
+ def filter_backtrace(backtrace)
116
+ @filters.each do |f|
117
+ backtrace = backtrace.map { |line| f.call(line) }
118
+ end
119
+
120
+ backtrace
121
+ end
122
+
123
+ def silence(backtrace)
124
+ @silencers.each do |s|
125
+ backtrace = backtrace.reject { |line| s.call(line) }
126
+ end
127
+
128
+ backtrace
129
+ end
130
+
131
+ def noise(backtrace)
132
+ backtrace - silence(backtrace)
133
+ end
134
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backtrace_cleaner
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Igor S. Morozov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - igor@morozov.is
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - LICENSE_ACTIVE_SUPPORT.txt
70
+ - README.md
71
+ - Rakefile
72
+ - backtrace_cleaner.gemspec
73
+ - bin/console
74
+ - bin/setup
75
+ - lib/backtrace_cleaner.rb
76
+ - lib/backtrace_cleaner/version.rb
77
+ homepage: https://github.com/Morozzzko
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.7.6
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: BacktraceCleaner from ActiveSupport without any ActiveSupport
101
+ test_files: []