smart_polling 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c3fbb33f705c7552b7b63192ef9ca21c01b2d8f
4
+ data.tar.gz: eb8bde39fa7b97612040f30b621e4c5d418da510
5
+ SHA512:
6
+ metadata.gz: be8001770d19772c9c160b40f717adcd645a722f838b817cc07f56fb6c0cd88b465485183a9c9304645f1d7da9d3988b95992680f1c5cf1927778d1657ccf65a
7
+ data.tar.gz: 8223f4b80b67199f2a998901181f403932608cc1ccc83ab70a229ae956945ebf5b31533aab4f822f2f35c28a512a1dfaa1bc87e02de4b97276799b10b1b8f22e
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format documentation
3
+ --profile
4
+ --tty
@@ -0,0 +1 @@
1
+ midi_lyrics
@@ -0,0 +1 @@
1
+ 2.2.0
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - "2.1"
7
+ - "2.2"
8
+ - ruby-head
9
+ - jruby-19mode
10
+ - jruby-head
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smart_polling.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'simplecov', :require => false
8
+ gem 'coveralls', :require => false
9
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Mateus Del Bianco
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ task :default => :spec
4
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,18 @@
1
+ require "smart_polling/version"
2
+
3
+ class SmartPolling
4
+ class TimeoutError < StandardError; end
5
+
6
+ def self.poll(seconds: 10, delay: 1, timeout_error: nil)
7
+ timeout_error ||= TimeoutError.new
8
+ time_limit = Time.now + seconds
9
+
10
+ while Time.now < time_limit do
11
+ result = yield
12
+ return result if result
13
+ sleep delay
14
+ end
15
+
16
+ raise timeout_error
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ class SmartPolling
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smart_polling/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "smart_polling"
8
+ spec.version = SmartPolling::VERSION
9
+ spec.authors = ["Mateus Del Bianco"]
10
+ spec.email = ["mateus@delbianco.net.br"]
11
+ spec.summary = %q{SmartPolling is your favorite watchdog timer.}
12
+ spec.description = %q{SmartPolling makes sure your code is still alive, barking out loud if there's silence for too long.}
13
+ spec.homepage = "https://github.com/mateusdelbianco/smart_polling"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe SmartPolling do
4
+ describe "poll" do
5
+ context "returning false" do
6
+ let(:block) { -> { false } }
7
+
8
+ it "raises SmartPolling::TimeoutError" do
9
+ expect { SmartPolling.poll(seconds: 0.2, delay: 0.05, &block) }.
10
+ to raise_error(SmartPolling::TimeoutError)
11
+ end
12
+
13
+ it "raises a custom error" do
14
+ expect { SmartPolling.poll(seconds: 0.2, delay: 0.05, timeout_error: StandardError.new("custom_error"), &block) }.
15
+ to raise_error(StandardError, "custom_error")
16
+ end
17
+ end
18
+
19
+ context "returning true after some calls" do
20
+ let(:block) do
21
+ values = [false, false, "return_value", "another_return_value"]
22
+ -> { values.shift }
23
+ end
24
+
25
+ it "returns the first non-false value" do
26
+ expect(SmartPolling.poll(seconds: 0.2, delay: 0.05, &block)).to eq("return_value")
27
+ end
28
+ end
29
+
30
+ context "returning some value" do
31
+ let(:block) { -> { "return_value" } }
32
+
33
+ it "returns the value" do
34
+ expect(SmartPolling.poll(seconds: 0.2, delay: 0.05, &block)).to eq("return_value")
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require "simplecov"
8
+ require "coveralls"
9
+
10
+ class SimpleCov::Formatter::MergedFormatter
11
+ def format(result)
12
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
13
+ Coveralls::SimpleCov::Formatter.new.format(result)
14
+ end
15
+ end
16
+ SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
17
+ SimpleCov.start do
18
+ add_filter "spec"
19
+ end
20
+
21
+ require "smart_polling"
22
+
23
+ RSpec.configure do |config|
24
+ config.run_all_when_everything_filtered = true
25
+ config.filter_run :focus
26
+
27
+ # Run specs in random order to surface order dependencies. If you find an
28
+ # order dependency and want to debug it, you can fix the order by providing
29
+ # the seed, which is printed after each run.
30
+ # --seed 1234
31
+ config.order = 'random'
32
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_polling
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mateus Del Bianco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-24 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
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
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
+ description: SmartPolling makes sure your code is still alive, barking out loud if
56
+ there's silence for too long.
57
+ email:
58
+ - mateus@delbianco.net.br
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".ruby-gemset"
66
+ - ".ruby-version"
67
+ - ".travis.yml"
68
+ - Gemfile
69
+ - LICENSE.txt
70
+ - Rakefile
71
+ - lib/smart_polling.rb
72
+ - lib/smart_polling/version.rb
73
+ - smart_polling.gemspec
74
+ - spec/smart_polling_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: https://github.com/mateusdelbianco/smart_polling
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.8
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: SmartPolling is your favorite watchdog timer.
100
+ test_files:
101
+ - spec/smart_polling_spec.rb
102
+ - spec/spec_helper.rb
103
+ has_rdoc: