Merge branch 'hotfix-1.1.1'
This commit is contained in:
commit
2b0b3d94d1
@ -1,7 +1,7 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
fast_jsonapi (1.1.0)
|
||||
fast_jsonapi (1.1.1)
|
||||
activesupport (>= 4.2)
|
||||
|
||||
GEM
|
||||
|
@ -1,6 +1,6 @@
|
||||
Gem::Specification.new do |gem|
|
||||
gem.name = "fast_jsonapi"
|
||||
gem.version = "1.1.0"
|
||||
gem.version = "1.1.1"
|
||||
|
||||
gem.required_rubygems_version = Gem::Requirement.new(">= 0") if gem.respond_to? :required_rubygems_version=
|
||||
gem.metadata = { "allowed_push_host" => "https://rubygems.org" } if gem.respond_to? :metadata=
|
||||
|
@ -12,7 +12,12 @@ module FastJsonapi
|
||||
# e.g. https://github.com/github/github-ds/blob/fbda5389711edfb4c10b6c6bad19311dfcb1bac1/lib/github/result.rb
|
||||
class Result
|
||||
def initialize(*rescued_exceptions)
|
||||
rescued_exceptions = [StandardError] if rescued_exceptions.empty?
|
||||
@rescued_exceptions = if rescued_exceptions.empty?
|
||||
[StandardError]
|
||||
else
|
||||
rescued_exceptions
|
||||
end
|
||||
|
||||
@value = yield
|
||||
@error = nil
|
||||
rescue *rescued_exceptions => e
|
||||
@ -33,7 +38,8 @@ module FastJsonapi
|
||||
|
||||
def rescue
|
||||
return self if ok?
|
||||
Result.new { yield(@error) }
|
||||
|
||||
Result.new(*@rescued_exceptions) { yield(@error) }
|
||||
end
|
||||
end
|
||||
|
||||
|
21
spec/lib/multi_to_json/result_spec.rb
Normal file
21
spec/lib/multi_to_json/result_spec.rb
Normal file
@ -0,0 +1,21 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module FastJsonapi
|
||||
module MultiToJson
|
||||
describe Result do
|
||||
it 'supports chaining of rescues' do
|
||||
expect do
|
||||
Result.new(LoadError) do
|
||||
require '1'
|
||||
end.rescue do
|
||||
require '2'
|
||||
end.rescue do
|
||||
require '3'
|
||||
end.rescue do
|
||||
'4'
|
||||
end
|
||||
end.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user