try-for 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +16 -0
  3. data/Rakefile +1 -0
  4. data/lib/try-for.rb +15 -0
  5. data/try-for.gemspec +21 -0
  6. metadata +62 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c963d9bfa7ce9aad5edda3375562b0b00d266147
4
+ data.tar.gz: e1c1c791f0b39cd2212fce2971ae73a1fe962eb7
5
+ SHA512:
6
+ metadata.gz: fdf540cadfe1314ebc52056be34a0bbe12e17df4e590462f6769ab151b51cf24d9e994d8bc71eca01032ed7e7c31c56a6448277110891fa81a6715c7893500ae
7
+ data.tar.gz: 962faf1c3c5ed3995e19454fa6dcd3106bc507a50f898ed3be7ca4f2350b0bedeecb3fbbceed8799f7bab8375fda76d9c69f96f5ecb2019097af882b5c344a12
@@ -0,0 +1,16 @@
1
+ # TryFor
2
+
3
+ Let you try block code for a X seconds capturing exceptions.
4
+
5
+ ## RSpec
6
+
7
+ ```ruby
8
+ require "rails_helper"
9
+ require 'try-for'
10
+
11
+ RSpec.describe 'Example' do
12
+ it 'works ok' do
13
+ try_for(2) { expect(page).to have_css('#page_id') }
14
+ end
15
+ end
16
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ def try_for(seconds)
2
+ time = Time.now.to_i
3
+ success = false
4
+
5
+ while !success and Time.now.to_i - time < seconds do
6
+ begin
7
+ yield
8
+ success = true
9
+ rescue Exception
10
+ sleep 0.1
11
+ end
12
+ end
13
+
14
+ yield unless success
15
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "try-for"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Rafael Jurado"]
9
+ spec.email = ["rjurado01@gmail.com"]
10
+ spec.summary = %q{Try block code for a X seconds capturing exceptions.}
11
+ spec.description = %q{Try block code for a X seconds capturing exceptions.}
12
+ spec.homepage = "https://github.com/rjurado01/try-for"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: try-for
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rafael Jurado
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ description: Try block code for a X seconds capturing exceptions.
28
+ email:
29
+ - rjurado01@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - Rakefile
36
+ - lib/try-for.rb
37
+ - try-for.gemspec
38
+ homepage: https://github.com/rjurado01/try-for
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.5.1
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Try block code for a X seconds capturing exceptions.
62
+ test_files: []