recoverable 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3cd84a75cc65ec1edb7af123525092ef9f0194a
4
- data.tar.gz: def900fb2218f4dd57e45f7f7abc1b8ced7ceffe
3
+ metadata.gz: dcb4ca3801d95816c2f2fc8c7219d4ae77b86738
4
+ data.tar.gz: d804c1e859e19de3ac18d2c3cf0bbedc809004a0
5
5
  SHA512:
6
- metadata.gz: 51bea1cac9ba766e6739541e6a5b83a77787a38c7315c100ee1f9ea421c851ac476d9bb97e4b6e5626314c1bfde5c8ebf28467f9ed9a47531cd78cfdff550ec2
7
- data.tar.gz: 2b86282e90d387b9655d7ae312295b82a6ff92790d15eab23cef8b99bc8ed2c297683918b1b33e663897ad305f23e589d7015e921c35ffd41bffa4f2c170cbe0
6
+ metadata.gz: 9357f909a7e4a17fd79fb24257c9df343fa874a85d769d665f7ecae1c2a452ef8d4dcd602409d8c4781280b1a6735e5f747dc03a152d205d5a45a4f52f3d7b30
7
+ data.tar.gz: d1757b043a62dbab6f9f9f5e148a3d931f68ad0e00c107ea630cf160a490e14ebcd3f7833128b879b15e617dd653c6bda829294832bcf250273bca0d1ff0a0b6
data/README.md CHANGED
@@ -138,7 +138,7 @@ Recoverable also allows you to configure a custom error handling method. This sh
138
138
  baz
139
139
  end
140
140
 
141
- def handle_error(:error)
141
+ def handle_error(error:)
142
142
  "#{error} was retried twice, raised and then this method was called."
143
143
  end
144
144
  end
@@ -33,46 +33,13 @@ module Recoverable
33
33
  req_params = retrieve_required_parameters(instance, custom_handler)
34
34
 
35
35
  return instance.send(custom_handler) if req_params.empty?
36
-
37
- custom_handler_args = fetch_handler_args(args, instance, req_params, error)
38
- instance.send(custom_handler, custom_handler_args)
36
+ instance.send(custom_handler, *args, { error: error })
39
37
  end
40
38
 
41
39
  def retrieve_required_parameters(instance, custom_handler)
42
40
  unbound_method = instance.class.instance_method(custom_handler)
43
41
  unbound_method.parameters.map{|p| p[1] if p[0] == :keyreq }.compact
44
42
  end
45
-
46
- def fetch_handler_args(args, instance, req_params, error)
47
- custom_handler_args = {error: error}
48
- local_args = fetch_local_args(args)
49
- evaluateables = evaluateable_keys_on(instance)
50
- generate_custom_handler_args(req_params: req_params, evaluateables: evaluateables, local_args: local_args, instance: instance, custom_handler_args: custom_handler_args)
51
- end
52
-
53
- def generate_custom_handler_args(req_params:, evaluateables:, local_args:, instance:, custom_handler_args:)
54
- req_params.each do |key|
55
- custom_handler_args[key] = instance.send(:eval, key.to_s) if evaluateables.include?(key)
56
- custom_handler_args[key] ||= local_args[key] if local_args.keys.include?(key)
57
- end
58
-
59
- custom_handler_args
60
- end
61
-
62
- def fetch_instance_variables(instance)
63
- instance_variables.map { |name| name[1..-1].to_sym }
64
- end
65
-
66
- def fetch_local_args(args)
67
- args.map(&:to_a).flatten(1).to_h
68
- end
69
-
70
- def evaluateable_keys_on(instance)
71
- fetch_instance_variables(instance) +
72
- instance.send(:public_methods) +
73
- instance.send(:local_variables)
74
- end
75
-
76
43
  end
77
44
 
78
45
 
@@ -1,3 +1,3 @@
1
1
  module Recoverable
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -214,24 +214,24 @@ RSpec.describe Recoverable do
214
214
  extend Recoverable
215
215
  recover :bar, tries: 2, on: CustomError, custom_handler: :handle_error
216
216
 
217
- def bar(arg:nil)
217
+ def bar(string, array, arg: nil)
218
218
  baz
219
219
  end
220
220
 
221
221
  def baz; end
222
222
 
223
- def handle_error(error:, arg:)
224
- arg
223
+ def handle_error(*args, error:)
224
+ args
225
225
  end
226
226
 
227
227
  end
228
228
 
229
- subject { instance.bar(arg: "I'm a keyword Arg")}
229
+ subject { instance.bar('foo', ['bar', 'baz'], arg: "I'm a keyword Arg")}
230
230
 
231
231
  it "has access to the keyword args" do
232
232
  allow_any_instance_of(self.class::TestClass).to receive(:baz).and_raise(CustomError)
233
233
  expect{ subject }.to_not raise_error(Recoverable::RetryCountExceeded)
234
- expect(subject).to eq("I'm a keyword Arg")
234
+ expect(subject).to eq(["foo", ["bar", "baz"], {:arg=>"I'm a keyword Arg"}])
235
235
  end
236
236
  end
237
237
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recoverable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Jacobs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-15 00:00:00.000000000 Z
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug