execute_with_rescue 0.0.1 → 0.0.2
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 +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +860 -0
- data/.travis.yml +18 -6
- data/Appraisals +15 -6
- data/CHANGELOG.md +38 -3
- data/Gemfile +2 -2
- data/README.md +7 -11
- data/Rakefile +9 -7
- data/execute_with_rescue.gemspec +17 -12
- data/gemfiles/rails_4_0.gemfile +2 -2
- data/gemfiles/rails_4_1.gemfile +2 -2
- data/gemfiles/{rails_3_2.gemfile → rails_4_2.gemfile} +2 -2
- data/gemfiles/rails_5_0.gemfile +7 -0
- data/lib/execute_with_rescue/mixins/core.rb +46 -34
- data/lib/execute_with_rescue/version.rb +1 -1
- data/lib/execute_with_rescue.rb +3 -3
- data/spec/core_spec.rb +73 -67
- data/spec/fixtures/test_service_classes.rb +9 -7
- data/spec/spec_helper.rb +7 -6
- metadata +68 -38
data/.travis.yml
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
+
# Send builds to container-based infrastructure
|
|
2
|
+
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
|
3
|
+
sudo: false
|
|
1
4
|
language: ruby
|
|
2
5
|
cache:
|
|
3
|
-
|
|
6
|
+
- bundler
|
|
4
7
|
rvm:
|
|
5
|
-
- 1.
|
|
6
|
-
- 2.
|
|
7
|
-
- 2.
|
|
8
|
-
-
|
|
8
|
+
- 2.1.10
|
|
9
|
+
- 2.2.6
|
|
10
|
+
- 2.3.3
|
|
11
|
+
- ruby-head
|
|
9
12
|
gemfile:
|
|
10
|
-
- gemfiles/rails_3_2.gemfile
|
|
11
13
|
- gemfiles/rails_4_0.gemfile
|
|
12
14
|
- gemfiles/rails_4_1.gemfile
|
|
15
|
+
- gemfiles/rails_4_2.gemfile
|
|
16
|
+
matrix:
|
|
17
|
+
fast_finish: true
|
|
18
|
+
allow_failures:
|
|
19
|
+
- rvm: ruby-head
|
|
20
|
+
include:
|
|
21
|
+
- rvm: 2.3.3
|
|
22
|
+
gemfile: gemfiles/rails_5_0.gemfile
|
|
23
|
+
- rvm: ruby-head
|
|
24
|
+
gemfile: gemfiles/rails_5_0.gemfile
|
|
13
25
|
|
data/Appraisals
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
appraise "
|
|
2
|
-
|
|
1
|
+
appraise "rails_4_0" do
|
|
2
|
+
version = "~> 4.0.12"
|
|
3
|
+
gem "activesupport", version
|
|
3
4
|
end
|
|
4
5
|
|
|
5
|
-
appraise "
|
|
6
|
-
|
|
6
|
+
appraise "rails_4_1" do
|
|
7
|
+
version = "~> 4.1.8"
|
|
8
|
+
gem "activesupport", version
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
appraise "
|
|
10
|
-
|
|
11
|
+
appraise "rails_4_2" do
|
|
12
|
+
version = "~> 4.2.0"
|
|
13
|
+
gem "activesupport", version
|
|
11
14
|
end
|
|
15
|
+
|
|
16
|
+
appraise "rails_5_0" do
|
|
17
|
+
version = "~> 5.0.0"
|
|
18
|
+
gem "activesupport", version
|
|
19
|
+
end
|
|
20
|
+
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
# Change Log
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## [Unreleased]
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- Nothing
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Nothing
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Nothing
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## [0.0.2] - 2016-12-23
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- Add support for AR 5.0.x
|
|
26
|
+
- Drop support for AR 3.x
|
|
27
|
+
- Drop support for Ruby < 2.1
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## 0.0.1 - 2014-03-26
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- Initial Release
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
[0.0.2]: https://github.com/AssetSync/asset_sync/compare/v0.0.2...HEAD
|
|
38
|
+
[Unreleased]: https://github.com/AssetSync/asset_sync/compare/v0.0.1...v0.0.2
|
|
2
39
|
|
|
3
40
|
|
|
4
|
-
- **0.0.1**
|
|
5
|
-
- Initail Release
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -10,17 +10,13 @@ Calling `airbrake` manually sometimes is the best option, but not all the time.
|
|
|
10
10
|
I might release another gem for that airbrake adapter.
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
##
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
[](http://badge.fury.io/rb/execute_with_rescue)
|
|
21
|
-
[](https://gemnasium.com/PikachuEXE/execute_with_rescue)
|
|
22
|
-
[](https://coveralls.io/r/PikachuEXE/execute_with_rescue)
|
|
23
|
-
[](https://codeclimate.com/github/PikachuEXE/execute_with_rescue)
|
|
13
|
+
## Status
|
|
14
|
+
|
|
15
|
+
[](https://travis-ci.org/PikachuEXE/execute_with_rescue)
|
|
16
|
+
[](http://badge.fury.io/rb/execute_with_rescue)
|
|
17
|
+
[](https://gemnasium.com/PikachuEXE/execute_with_rescue)
|
|
18
|
+
[](https://coveralls.io/r/PikachuEXE/execute_with_rescue)
|
|
19
|
+
[](https://codeclimate.com/github/PikachuEXE/execute_with_rescue)
|
|
24
20
|
|
|
25
21
|
|
|
26
22
|
## Installation
|
data/Rakefile
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
require "bundler/gem_tasks"
|
|
2
|
-
require "rubygems"
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
|
|
5
|
-
require "rspec/core/rake_task"
|
|
6
1
|
require "appraisal"
|
|
2
|
+
require "bundler"
|
|
3
|
+
require "rspec/core/rake_task"
|
|
4
|
+
require "rubocop/rake_task"
|
|
5
|
+
|
|
6
|
+
Bundler::GemHelper.install_tasks
|
|
7
7
|
|
|
8
8
|
RSpec::Core::RakeTask.new(:spec)
|
|
9
9
|
|
|
10
|
+
RuboCop::RakeTask.new(:rubocop)
|
|
11
|
+
|
|
10
12
|
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
|
|
11
13
|
task :default do
|
|
12
|
-
sh "
|
|
14
|
+
sh "appraisal install && rake appraisal spec"
|
|
13
15
|
end
|
|
14
16
|
else
|
|
15
|
-
task :
|
|
17
|
+
task default: [:spec]
|
|
16
18
|
end
|
data/execute_with_rescue.gemspec
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
|
-
lib = File.expand_path(
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require
|
|
4
|
+
require "execute_with_rescue/version"
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "execute_with_rescue"
|
|
8
8
|
spec.version = ExecuteWithRescue::VERSION
|
|
9
9
|
spec.authors = ["PikachuEXE"]
|
|
10
10
|
spec.email = ["pikachuexe@gmail.com"]
|
|
11
|
-
spec.summary =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
spec.summary = <<-SUMMARY
|
|
12
|
+
Execute code without writting rescue in methods with before and after hooks.
|
|
13
|
+
You can also create some extensions yourself.
|
|
14
|
+
SUMMARY
|
|
15
|
+
spec.description = <<-DESC
|
|
16
|
+
Saves your from writing `begin...rescue...ensure...end` everywhere.
|
|
17
|
+
This assumes you know how to use `rescue_from` not just within a controller.
|
|
18
|
+
DESC
|
|
16
19
|
spec.homepage = "http://github.com/PikachuEXE/execute_with_rescue"
|
|
17
20
|
spec.license = "MIT"
|
|
18
21
|
|
|
@@ -21,16 +24,18 @@ Gem::Specification.new do |spec|
|
|
|
21
24
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
22
25
|
spec.require_paths = ["lib"]
|
|
23
26
|
|
|
24
|
-
spec.add_dependency "activesupport", ">=
|
|
27
|
+
spec.add_dependency "activesupport", ">= 4.0.0", "< 5.1.0"
|
|
25
28
|
|
|
26
29
|
spec.add_development_dependency "bundler", "~> 1.5"
|
|
27
|
-
spec.add_development_dependency "rake"
|
|
28
|
-
spec.add_development_dependency "appraisal", "
|
|
29
|
-
spec.add_development_dependency "rspec", "~>
|
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
31
|
+
spec.add_development_dependency "appraisal", "~> 2.0"
|
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
33
|
+
spec.add_development_dependency "rspec-its", "~> 1.0"
|
|
30
34
|
spec.add_development_dependency "coveralls", ">= 0.7"
|
|
31
35
|
spec.add_development_dependency "gem-release", ">= 0.7"
|
|
36
|
+
spec.add_development_dependency "rubocop", "~> 0.30"
|
|
32
37
|
|
|
33
|
-
spec.required_ruby_version = ">= 1.
|
|
38
|
+
spec.required_ruby_version = ">= 2.1.0"
|
|
34
39
|
|
|
35
40
|
spec.required_rubygems_version = ">= 1.4.0"
|
|
36
41
|
end
|
data/gemfiles/rails_4_0.gemfile
CHANGED
data/gemfiles/rails_4_1.gemfile
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
1
|
+
require "active_support/concern"
|
|
2
|
+
require "active_support/rescuable"
|
|
3
|
+
require "active_support/core_ext/class/attribute"
|
|
4
4
|
|
|
5
|
-
require
|
|
5
|
+
require "execute_with_rescue/errors"
|
|
6
6
|
|
|
7
7
|
module ExecuteWithRescue
|
|
8
8
|
module Mixins
|
|
@@ -13,13 +13,17 @@ module ExecuteWithRescue
|
|
|
13
13
|
include ActiveSupport::Rescuable
|
|
14
14
|
|
|
15
15
|
# Use active support or inheritance will be broken
|
|
16
|
-
class_attribute
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
class_attribute(
|
|
17
|
+
:_execute_with_rescue_before_hooks,
|
|
18
|
+
instance_reader: true,
|
|
19
|
+
instance_writer: false,
|
|
20
|
+
)
|
|
19
21
|
self._execute_with_rescue_before_hooks = []
|
|
20
|
-
class_attribute
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
class_attribute(
|
|
23
|
+
:_execute_with_rescue_after_hooks,
|
|
24
|
+
instance_reader: true,
|
|
25
|
+
instance_writer: false,
|
|
26
|
+
)
|
|
23
27
|
self._execute_with_rescue_after_hooks = []
|
|
24
28
|
|
|
25
29
|
class << self
|
|
@@ -45,14 +49,16 @@ module ExecuteWithRescue
|
|
|
45
49
|
# Must use setter to avoid changing parent setting
|
|
46
50
|
self._execute_with_rescue_before_hooks =
|
|
47
51
|
[
|
|
48
|
-
|
|
52
|
+
_execute_with_rescue_before_hooks,
|
|
49
53
|
# Add method names first, block later
|
|
50
54
|
method_names,
|
|
51
55
|
block,
|
|
52
56
|
].flatten.compact
|
|
53
57
|
end
|
|
54
|
-
alias_method
|
|
55
|
-
|
|
58
|
+
alias_method(
|
|
59
|
+
:add_execute_with_rescue_before_hook,
|
|
60
|
+
:add_execute_with_rescue_before_hooks,
|
|
61
|
+
)
|
|
56
62
|
|
|
57
63
|
# Pass method names or/and a block to be executed after yield
|
|
58
64
|
# Similar to add_execute_with_rescue_before_hooks
|
|
@@ -64,23 +70,25 @@ module ExecuteWithRescue
|
|
|
64
70
|
# Must use setter to avoid changing parent setting
|
|
65
71
|
self._execute_with_rescue_after_hooks =
|
|
66
72
|
[
|
|
67
|
-
|
|
73
|
+
_execute_with_rescue_after_hooks,
|
|
68
74
|
# Add method names first, block later
|
|
69
75
|
method_names,
|
|
70
76
|
block,
|
|
71
77
|
].flatten.compact
|
|
72
78
|
end
|
|
73
|
-
alias_method
|
|
74
|
-
|
|
79
|
+
alias_method(
|
|
80
|
+
:add_execute_with_rescue_after_hook,
|
|
81
|
+
:add_execute_with_rescue_after_hooks,
|
|
82
|
+
)
|
|
75
83
|
|
|
76
|
-
# @private
|
|
84
|
+
# @api private
|
|
77
85
|
# @discuss
|
|
78
86
|
# Should this moved into another module?
|
|
79
87
|
# (without being mixed in)
|
|
80
88
|
def _validate_execute_with_rescue_hook!(method_names, block)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
method_names.all?{|m| m.is_a?(Symbol)}
|
|
89
|
+
fail ArgumentError if method_names.empty? && block.nil?
|
|
90
|
+
fail ExecuteWithRescue::Errors::UnsupportedHookValue unless
|
|
91
|
+
method_names.all? { |m| m.is_a?(Symbol) }
|
|
84
92
|
end
|
|
85
93
|
end
|
|
86
94
|
end
|
|
@@ -91,7 +99,7 @@ module ExecuteWithRescue
|
|
|
91
99
|
# after you have call `rescue_from` at class level
|
|
92
100
|
# This saves you from typing:
|
|
93
101
|
# ```
|
|
94
|
-
#
|
|
102
|
+
# begin
|
|
95
103
|
# # Some code that might cause exception
|
|
96
104
|
# rescue
|
|
97
105
|
# rescue_with_handler(exception) || raise
|
|
@@ -102,6 +110,8 @@ module ExecuteWithRescue
|
|
|
102
110
|
# You can use `alias_method` to create a shorter alias, I use `execute`
|
|
103
111
|
# But some gem might use that name already, so be careful
|
|
104
112
|
#
|
|
113
|
+
# @api
|
|
114
|
+
#
|
|
105
115
|
# @param block [Proc]
|
|
106
116
|
# a block to be executed
|
|
107
117
|
#
|
|
@@ -129,44 +139,46 @@ module ExecuteWithRescue
|
|
|
129
139
|
_run_execute_with_rescue_before_hooks
|
|
130
140
|
yield
|
|
131
141
|
rescue Exception => exception
|
|
132
|
-
rescue_with_handler(exception) ||
|
|
142
|
+
rescue_with_handler(exception) || fail
|
|
133
143
|
ensure
|
|
134
144
|
_run_execute_with_rescue_after_hooks
|
|
135
145
|
end
|
|
136
146
|
|
|
137
|
-
# @private
|
|
147
|
+
# @api private
|
|
138
148
|
def _run_execute_with_rescue_before_hooks
|
|
139
149
|
_execute_with_rescue_before_hooks.each do |before_hook|
|
|
140
150
|
_run_execute_with_rescue_hook(before_hook)
|
|
141
151
|
end
|
|
142
152
|
end
|
|
143
153
|
|
|
144
|
-
# @private
|
|
154
|
+
# @api private
|
|
145
155
|
def _run_execute_with_rescue_after_hooks
|
|
146
|
-
_execute_with_rescue_after_hooks.
|
|
156
|
+
_execute_with_rescue_after_hooks.reverse_each do |after_hook|
|
|
147
157
|
_run_execute_with_rescue_hook(after_hook)
|
|
148
158
|
end
|
|
149
159
|
end
|
|
150
160
|
|
|
151
|
-
# @private
|
|
161
|
+
# @api private
|
|
152
162
|
def _run_execute_with_rescue_hook(method_name_or_block)
|
|
153
163
|
case method_name_or_block
|
|
154
164
|
when Symbol
|
|
155
|
-
|
|
156
|
-
self.send(method_name_or_block)
|
|
157
|
-
rescue NoMethodError
|
|
158
|
-
raise ExecuteWithRescue::Errors::NoHookMethod,
|
|
159
|
-
"method `#{method_name_or_block}` does not exists"
|
|
160
|
-
end
|
|
161
|
-
# block are converted to Proc as argument
|
|
165
|
+
_run_execute_with_rescue_hook_with_symbol(method_name_or_block)
|
|
162
166
|
when Proc
|
|
167
|
+
# block are converted to Proc as argument
|
|
163
168
|
instance_eval(&method_name_or_block)
|
|
164
169
|
else
|
|
165
170
|
# This should not happen unless someone tamper the class attribute
|
|
166
171
|
# without using the provided methods
|
|
167
|
-
|
|
172
|
+
fail ExecuteWithRescue::Errors::UnsupportedHookValue
|
|
168
173
|
end
|
|
169
174
|
end
|
|
175
|
+
|
|
176
|
+
def _run_execute_with_rescue_hook_with_symbol(method_name)
|
|
177
|
+
send(method_name)
|
|
178
|
+
rescue NoMethodError
|
|
179
|
+
fail ExecuteWithRescue::Errors::NoHookMethod,
|
|
180
|
+
"method `#{method_name}` does not exists"
|
|
181
|
+
end
|
|
170
182
|
end
|
|
171
183
|
end
|
|
172
184
|
end
|
data/lib/execute_with_rescue.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
1
|
+
require "execute_with_rescue/version"
|
|
2
|
+
require "execute_with_rescue/errors"
|
|
3
|
+
require "execute_with_rescue/mixins/core"
|
|
4
4
|
|
|
5
5
|
module ExecuteWithRescue
|
|
6
6
|
end
|