snoop 0.0.3 → 0.0.4

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: 611d593f137dee3cf2e533c2dc0a8e5d20f99e8b
4
- data.tar.gz: e12b2633526805a0bbacf0197308644278716308
3
+ metadata.gz: 0fd5c1237486ef935e48c655df057e062a2f73da
4
+ data.tar.gz: cab236fa1b0af6d51125a36d8955c8727e4cf22c
5
5
  SHA512:
6
- metadata.gz: 387dc11ed48e3e534915b06bab3ade86f50f72372b742d776e78f202679616ceb0897337cc559d457a9e61c9feffe56c4d29f54c6de11c27e4f9460e7f4f2b24
7
- data.tar.gz: e31a2bd0ca5015727ce06cb1877cc5c14ecc53b6ca81333e32385d017e1db2749588bbe92cb7027f334ae224ca705c2f4aa7b8c8ba05520b044d3438e68cf8a1
6
+ metadata.gz: 1afd73ec6e6fff288053c02213c68d14a20ae2f04706036a9a8ce81d30c5ad2694415dc00cba2d1d417cf3f554c6dbc985a44e1ac43e8a81e96b326ea03dba09
7
+ data.tar.gz: b3aa4b4d891f75a31a1ca9bafeea0e603f7600fcc7a753cfddd83e15ef066833b1b9a1bf597c2dc3ef77669e113a3a538818ff3a7030776caa2037d366594982
@@ -5,7 +5,14 @@ module Snoop
5
5
  class Http
6
6
  UrlRequiredException = Class.new(StandardError)
7
7
 
8
- attr_reader :url, :css, :http_client, :interval, :content
8
+ DEFAULT_OPTIONS = {
9
+ delay: 0,
10
+ count: 1,
11
+ while: -> { false },
12
+ until: -> { true }
13
+ }
14
+
15
+ attr_reader :url, :css, :http_client
9
16
  attr_accessor :content
10
17
 
11
18
  def initialize(url: nil, css: nil, http_client: HTTParty)
@@ -16,12 +23,16 @@ module Snoop
16
23
  @http_client = http_client
17
24
  end
18
25
 
19
- def notify(
20
- delay: 0, times: 1, while_true: -> { false }, while_false: -> { true }
21
- )
22
- while (times -= 1) >= 0 || while_true.call || !while_false.call
26
+ def notify(options = {})
27
+ options = DEFAULT_OPTIONS.merge(options)
28
+
29
+ while (
30
+ (options[:count] -= 1 ) >= 0 ||
31
+ options[:while].call ||
32
+ !options[:until].call
33
+ )
23
34
  yield content if content_changed?
24
- sleep delay
35
+ sleep options[:delay]
25
36
  end
26
37
  end
27
38
 
@@ -1,3 +1,3 @@
1
1
  module Snoop
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -8,7 +8,7 @@ describe Snoop::Http do
8
8
 
9
9
  notification_count = 0
10
10
 
11
- snoop.notify times: 2 do
11
+ snoop.notify count: 2 do
12
12
  notification_count += 1
13
13
  end
14
14
 
@@ -20,7 +20,7 @@ describe Snoop::Http do
20
20
 
21
21
  notification_count = 0
22
22
 
23
- snoop.notify times: 2 do
23
+ snoop.notify count: 2 do
24
24
  notification_count += 1
25
25
  end
26
26
 
@@ -44,7 +44,7 @@ describe Snoop::Http do
44
44
  it 'notifies the requested number of times' do
45
45
  notification_count = 0
46
46
 
47
- subject.notify times: 5 do
47
+ subject.notify count: 5 do
48
48
  notification_count += 1
49
49
  end
50
50
 
@@ -54,17 +54,17 @@ describe Snoop::Http do
54
54
  it 'notifies while an expression is true' do
55
55
  notification_count = 0
56
56
 
57
- subject.notify while_true: -> { notification_count < 3 } do
57
+ subject.notify while: -> { notification_count < 3 } do
58
58
  notification_count += 1
59
59
  end
60
60
 
61
61
  expect(notification_count).to eq 3
62
62
  end
63
63
 
64
- it 'notifies while an expression is false' do
64
+ it 'notifies until an expression is true' do
65
65
  notification_count = 0
66
66
 
67
- subject.notify while_false: -> { notification_count > 2 } do
67
+ subject.notify until: -> { notification_count > 2 } do
68
68
  notification_count += 1
69
69
  end
70
70
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snoop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hunt