soft_rescue 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 72bf57e66e0baedc513206bef4bee13f8713f793
4
+ data.tar.gz: ca0a766f36c70341a0929682b416dc4791e4296f
5
+ SHA512:
6
+ metadata.gz: 56cd91530763d61612897616b0bd6ddae48b33e1140602662c181d52134d211c58c3a22d69e1fed07693f5bff9557882a94818839215239ecef0fdd6be982b39
7
+ data.tar.gz: d4350d8fb462ace032467d5deeba703b48785535a4a5cd63952a8d669eb373fad48dfe43fab2b6504f5b425b628b1a57aa03b1e113f51b52cc089c77fd02cc66
data/.codeclimate.yml ADDED
@@ -0,0 +1,22 @@
1
+ ---
2
+ engines:
3
+ bundler-audit:
4
+ enabled: true
5
+ duplication:
6
+ enabled: true
7
+ config:
8
+ languages:
9
+ - ruby
10
+ fixme:
11
+ enabled: true
12
+ rubocop:
13
+ enabled: true
14
+ flog:
15
+ enabled: true
16
+ reek:
17
+ enabled: true
18
+ ratings:
19
+ paths:
20
+ - Gemfile.lock
21
+ exclude_paths:
22
+ - test/
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ AllCops:
2
+ Exclude:
3
+ - bin/**/*
4
+ - bin/**/*
5
+ - vendor/**/*
6
+ - soft_rescue.gemspec
7
+
8
+ Metrics/LineLength:
9
+ Enabled: true
10
+ Max: 120
11
+
12
+ Metrics/ClassLength:
13
+ Enabled: true
14
+ Exclude:
15
+ - test/**/*
16
+
17
+ Metrics/BlockLength:
18
+ Enabled: true
19
+ Exclude:
20
+ - test/**/*
21
+
22
+ Style/Documentation:
23
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=06374bbaa94d2478c1aa5d61fc4d15d64d08ec47c6a20d2636f6efe119092189
4
+ language: ruby
5
+ rvm:
6
+ - 2.2.0
7
+ before_install: gem install bundler -v 1.14.5
8
+ before_script:
9
+ - bundle install
10
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
11
+ - chmod +x ./cc-test-reporter
12
+ - ./cc-test-reporter before-build
13
+ script:
14
+ - bundle exec rubocop
15
+ - bundle exec rake test
16
+ after_script:
17
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -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 sergey.staskov@dellin.ru. 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,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in soft_rescue.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rake'
8
+ gem 'rubocop'
9
+ gem 'simplecov'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ soft_rescue (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.3.0)
10
+ docile (1.1.5)
11
+ json (2.1.0)
12
+ minitest (5.10.3)
13
+ parallel (1.12.0)
14
+ parser (2.4.0.0)
15
+ ast (~> 2.2)
16
+ powerpack (0.1.1)
17
+ rainbow (2.2.2)
18
+ rake
19
+ rake (10.5.0)
20
+ rubocop (0.50.0)
21
+ parallel (~> 1.10)
22
+ parser (>= 2.3.3.1, < 3.0)
23
+ powerpack (~> 0.1)
24
+ rainbow (>= 2.2.2, < 3.0)
25
+ ruby-progressbar (~> 1.7)
26
+ unicode-display_width (~> 1.0, >= 1.0.1)
27
+ ruby-progressbar (1.9.0)
28
+ simplecov (0.15.0)
29
+ docile (~> 1.1.0)
30
+ json (>= 1.8, < 3)
31
+ simplecov-html (~> 0.10.0)
32
+ simplecov-html (0.10.2)
33
+ unicode-display_width (1.3.0)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 1.14)
40
+ minitest (~> 5.0)
41
+ rake
42
+ rubocop
43
+ simplecov
44
+ soft_rescue!
45
+
46
+ BUNDLED WITH
47
+ 1.14.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Sergey Staskov
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.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # SoftRescue
2
+
3
+ This gem helps to handle exceptions in soft manner using configured modes.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'soft_rescue'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install soft_rescue
20
+
21
+ ## Usage
22
+
23
+ ### Configuration
24
+ Code below may be placed to config/initializers/soft_rescue.rb (Rails) or anything like this file.
25
+
26
+ All params and whole block are optional.
27
+
28
+ ```ruby
29
+ SoftRescue.configure do |config|
30
+ config.logger = Logger.new
31
+ config.enabled = Rails.env.production?
32
+ config.capture_exception = -> exception { Raven.capture_exception(exception) }
33
+ end
34
+ ```
35
+
36
+ Use `SoftRescue.call` method not to raise exception, but just to log it and to return the result of on_failure.
37
+
38
+ ```ruby
39
+
40
+ SoftRescue.call(on_failure: -> { email_me_about_something_wrong; Time.now }) do
41
+ open("http://get-best-time") # raises StandardError
42
+ end
43
+ ```
44
+
45
+ Another example.
46
+
47
+ ```ruby
48
+ SoftRescue.call(on_failure: Time.now, message: "getting best time") do
49
+ open("http://get-best-time") # raises StandardError
50
+ end
51
+ ```
52
+
53
+ See more examples in test/
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ 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).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/soft_rescue. 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.
64
+
65
+
66
+ ## License
67
+
68
+ The gem is available as open source undhttps://travis-ci.org/solutus/soft_rescue.svg?branch=masterer the terms of the [MIT License](http://opensource.org/licenses/MIT).
69
+
70
+ ## Build statuses
71
+
72
+ [![Build Status](https://travis-ci.org/solutus/soft_rescue.svg)](https://travis-ci.org/solutus/soft_rescue)
73
+
74
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'soft_rescue'
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,3 @@
1
+ module SoftRescue
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,69 @@
1
+ require 'soft_rescue/version'
2
+
3
+ # SoftRescue provides logic to handle exception in soft manner.
4
+ module SoftRescue
5
+ # usage:
6
+ # SoftRescue.configure do |config|
7
+ # config.logger = Logger.new
8
+ # config.enabled = Rails.env.production?
9
+ # config.capture_exception = -> exception { Raven.capture_exception(exception) }
10
+ # end
11
+ def self.configure
12
+ yield Config
13
+ end
14
+
15
+ # usage:
16
+ # SoftRescue.call(on_failure: 0, message: "my custom exception info")
17
+ # SoftRescue.call(on_failure: -> { puts "fail!" }, message: "my custom exception info")
18
+ def self.call(on_failure: nil, message: nil)
19
+ yield
20
+ rescue StandardError => exception
21
+ ExceptionHandler.new(exception, on_failure, message).handle
22
+ end
23
+
24
+ module Config
25
+ class << self
26
+ # :reek:Attribute
27
+ attr_accessor :logger, :capture_exception, :enabled
28
+ end
29
+ end
30
+
31
+ # handles exceptions according to Config settings
32
+ class ExceptionHandler
33
+ def initialize(exception, on_failure, message)
34
+ @exception = exception
35
+ @on_failure = on_failure
36
+ @message = message
37
+ end
38
+
39
+ def handle
40
+ raise @exception unless Config.enabled
41
+ raise_alternative
42
+ end
43
+
44
+ private
45
+
46
+ def raise_alternative
47
+ log
48
+ capture_exception
49
+ handle_failure
50
+ end
51
+
52
+ def log
53
+ logger = Config.logger
54
+ return unless logger
55
+
56
+ logger.error [@message, @exception.message].compact.join('. ')
57
+ end
58
+
59
+ def capture_exception
60
+ capturer = Config.capture_exception
61
+ return unless capturer
62
+ capturer.call @exception
63
+ end
64
+
65
+ def handle_failure
66
+ @on_failure.is_a?(Proc) ? @on_failure.call : @on_failure
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soft_rescue/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'soft_rescue'
8
+ spec.version = SoftRescue::VERSION
9
+ spec.authors = ['Sergey Staskov']
10
+ spec.email = ['sergey.staskov@dellin.ru']
11
+
12
+ spec.summary = 'This gem helps to handle exceptions in soft manner using configured modes.'
13
+ spec.description = 'This gem helps to handle exceptions in soft manner using configured modes. Namely it can be configure not to raise exceptions but log it in systems like Sentry and Newrelic and return default value'
14
+ spec.homepage = 'https://github.com/solutus/soft_rescue'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ 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.14'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'minitest', '~> 5.0'
27
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soft_rescue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Staskov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-04 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: This gem helps to handle exceptions in soft manner using configured modes.
56
+ Namely it can be configure not to raise exceptions but log it in systems like Sentry
57
+ and Newrelic and return default value
58
+ email:
59
+ - sergey.staskov@dellin.ru
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".codeclimate.yml"
65
+ - ".gitignore"
66
+ - ".rubocop.yml"
67
+ - ".travis.yml"
68
+ - CODE_OF_CONDUCT.md
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - lib/soft_rescue.rb
77
+ - lib/soft_rescue/version.rb
78
+ - soft_rescue.gemspec
79
+ homepage: https://github.com/solutus/soft_rescue
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.6.12
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: This gem helps to handle exceptions in soft manner using configured modes.
103
+ test_files: []
104
+ has_rdoc: