kudan 1.0.0 → 2.0.0

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: 8ea854de313223f910383a383fa0333ec4324335
4
- data.tar.gz: 2fe01355f705afe64c1e1df24ad220df734a1f03
3
+ metadata.gz: 237d005c6fbd00ce363662958211e1353117110f
4
+ data.tar.gz: 211a4ee62a5c042f894968b31e0636749be68afe
5
5
  SHA512:
6
- metadata.gz: f2b421f0b98030dafe95adb8511fb992e301f812a7fe38c53baf0040d253ce3ae2a429866beb9864cc756bc5bf261fd7068cbcc13ec78265f085858ff9be32a7
7
- data.tar.gz: 6406e5f5e283554717053e7da5e91de3545e8a19c81e5ae9f8a8a992b7b426d61823f850568772929163243a286b9de916b91310a61a2c5f20e3fd057c161809
6
+ metadata.gz: b94c5fa6739c7cec047e3b173df186aed43b58e6995a2acfb27f5fcb2b05f28637d9e1283ae3e4eb8697eb438ccd8b3571a9aee56189e9667496246aa48a0bcf
7
+ data.tar.gz: d9c1cd24e5e6e4d945f7610401524d0ca89e614f19b09f85c6df228d22b023db8d9e4464bf0d0e70af98ab7dd62cfb7a16b78934f658c52871b3ac15c34eec0f
data/README.md CHANGED
@@ -13,7 +13,7 @@ Allow retry code blocks.
13
13
  ```ruby
14
14
  require 'kudan'
15
15
 
16
- Retryable.retryable(tries: 2, sleep_seconds: 0) do
16
+ Kudan.retryable(tries: 2, sleep_seconds: 0) do
17
17
  -- snip --
18
18
  end
19
19
  ```
@@ -1,7 +1,19 @@
1
1
  require 'active_support/configurable'
2
2
 
3
- class Configuration
4
- include ActiveSupport::Configurable
3
+ module Kudan
4
+ class Configuration
5
+ OPTIONS = [:enabled, :sleep_seconds, :tries].map(&:freeze).freeze
5
6
 
6
- config_accessor :enabled, :sleep_seconds, :tries
7
+ attr_accessor :enabled, :sleep_seconds, :tries
8
+
9
+ def initialize
10
+ @enabled = true
11
+ @tries = 2
12
+ @sleep_seconds = 1
13
+ end
14
+
15
+ def config
16
+ OPTIONS.map { |e| [e, send(e)] }.to_h
17
+ end
18
+ end
7
19
  end
data/lib/kudan/kudan.rb CHANGED
@@ -1,2 +1,43 @@
1
- require 'retryable'
1
+ require 'configuration'
2
2
  require 'version'
3
+
4
+ module Kudan
5
+ class << self
6
+ def disable
7
+ configuration.enabled = false
8
+ end
9
+
10
+ def enabled?
11
+ configuration.enabled
12
+ end
13
+
14
+ def enable
15
+ configuration.enabled = true
16
+ end
17
+
18
+ def configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+
22
+ def retryable(options = {})
23
+ opts = configuration.config.merge(options)
24
+ enabled = opts.fetch(:enabled)
25
+ sleep_seconds = opts.fetch(:sleep_seconds)
26
+ tries = opts.fetch(:tries)
27
+
28
+ retries = 0
29
+ retry_exception = nil
30
+ begin
31
+ yield retries, retry_exception
32
+ rescue StandardError => exception
33
+ raise unless enabled
34
+ raise if retries + 1 > tries
35
+
36
+ sleep(sleep_seconds)
37
+ retries += 1
38
+ retry_exception = exception
39
+ retry
40
+ end
41
+ end
42
+ end
43
+ end
data/lib/kudan/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kudan
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kudan
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - taki3
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-26 00:00:00.000000000 Z
11
+ date: 2017-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -70,7 +70,6 @@ files:
70
70
  - kudan.gemspec
71
71
  - lib/kudan/configuration.rb
72
72
  - lib/kudan/kudan.rb
73
- - lib/kudan/retryable.rb
74
73
  - lib/kudan/version.rb
75
74
  homepage: https://github.com/ayindi/kudan
76
75
  licenses:
@@ -92,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
91
  version: '0'
93
92
  requirements: []
94
93
  rubyforge_project:
95
- rubygems_version: 2.6.10
94
+ rubygems_version: 2.6.11
96
95
  signing_key:
97
96
  specification_version: 4
98
97
  summary: Allow retry code blocks
@@ -1,44 +0,0 @@
1
- require 'configuration'
2
-
3
- module Retryable
4
- Configuration.configure do |config|
5
- config.enabled = true
6
- config.sleep_seconds = 1
7
- config.tries = 2
8
- end
9
-
10
- class << self
11
- def disable
12
- Configuration.enabled = false
13
- end
14
-
15
- def enabled?
16
- Configuration.enabled
17
- end
18
-
19
- def enable
20
- Configuration.enabled = true
21
- end
22
-
23
- def retryable(options = {})
24
- opts = Configuration.config.merge(options)
25
- enabled = opts.fetch(:enabled)
26
- sleep_seconds = opts.fetch(:sleep_seconds)
27
- tries = opts.fetch(:tries)
28
-
29
- retries = 0
30
- retry_exception = nil
31
- begin
32
- yield retries, retry_exception
33
- rescue StandardError => exception
34
- raise unless enabled
35
- raise if retries + 1 > tries
36
-
37
- sleep(sleep_seconds)
38
- retries += 1
39
- retry_exception = exception
40
- retry
41
- end
42
- end
43
- end
44
- end