recoverable 0.0.1

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: 7a004cdad4e2c84084abd80d9f768e76e68ef82e
4
+ data.tar.gz: 619f7e3dfb8ecb873afaa6f63c1daab89afa022c
5
+ SHA512:
6
+ metadata.gz: 27fb6b8a72f506a7f19af2bafd2508a59bc61dd0582af89ab24105f7c36105c57ba42bcbbf8647d4104ad3a93ebb9cd90eef5e37094cdf8e9df0258cf90680f8
7
+ data.tar.gz: 0fb7fafc2453bbdbe8427acb02d904708c072fd78fe3c202e5ea587f4f064920640ae94bfccfaad1d2641ff37ddc27e3be9fc0a9dc978f943501ca60c359f6b8
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Ben Jacobs
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,21 @@
1
+ ## Recoverbale
2
+
3
+
4
+ ## Installation
5
+
6
+
7
+ ## Usage
8
+
9
+
10
+ ## How to contribute
11
+
12
+ * Fork the project
13
+ * Create your feature or bug fix
14
+ * Add the requried tests for it.
15
+ * Commit (do not change version or history)
16
+ * Send a pull request against the *development* branch
17
+
18
+ ## Copyright
19
+ Copyright (c) 2018 Ben Jacobs
20
+ Licenced under the MIT licence.
21
+
@@ -0,0 +1,46 @@
1
+ module Retryable
2
+ RetryCountExceeded = Class.new(StandardError)
3
+
4
+ def recover(method, times, on: [StandardError], sleep: 1, handler: nil)
5
+ recoverable = Array.wrap(on)
6
+ proxy = create_proxy(method, times, recoverable, sleep, handler)
7
+ self.prepend proxy
8
+ end
9
+
10
+ def create_proxy(method, times, recoverable, sleep, handler)
11
+ Module.new do
12
+ define_method(method) do |*args|
13
+ retries = times.dup
14
+ begin
15
+ super *args
16
+ rescue *recoverable => error
17
+ begin
18
+ sleep(sleep)
19
+ retries.next && retry
20
+ rescue StopIteration
21
+ if handler
22
+ handler_args = {}
23
+ unbound = self.class.instance_method(handler)
24
+ req_params = unbound.parameters.map{|p| p[1] if p[0] == :keyreq }.compact
25
+
26
+ return send(handler) if req_params.empty?
27
+
28
+ local_args = args.map(&:to_a).flatten(1).to_h
29
+ ivs = instance_values.keys.map(&:to_sym)
30
+
31
+ req_params.each do |key|
32
+ handler_args[key] ||= eval(key.to_s) if (ivs + public_methods + local_variables).include?(key)
33
+ handler_args[key] ||= local_args[key] if local_args.keys.include?(key)
34
+ end
35
+
36
+ send(handler, handler_args)
37
+ end
38
+ raise RetryCountExceeded, [error.class, error.message]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+
@@ -0,0 +1,3 @@
1
+ module Recoverable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ # require 'ship_station/version'
2
+ require 'active_support/all'
3
+ require 'logger'
4
+
5
+ # App
6
+ require 'recoverable/base'
7
+
8
+ # Models
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: recoverable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Jacobs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: her
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: Class Level retry DSL for ruby
98
+ email:
99
+ - benjaminpjacobs@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - MIT-LICENSE
105
+ - README.md
106
+ - lib/recoverable.rb
107
+ - lib/recoverable/base.rb
108
+ - lib/recoverable/version.rb
109
+ homepage:
110
+ licenses: []
111
+ metadata:
112
+ allowed_push_host: https://rubygems.org
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '2.3'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.14.1
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Class Level retry DSL for ruby
133
+ test_files: []