stockboy 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/stockboy/provider.rb +4 -0
- data/lib/stockboy/provider_repeater.rb +17 -3
- data/lib/stockboy/version.rb +1 -1
- data/spec/stockboy/job_spec.rb +2 -0
- data/spec/stockboy/provider_repeater_spec.rb +34 -6
- data/spec/stockboy/provider_spec.rb +33 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90e9bfd03d069c571ffd1e6e03dd018cf477289c
|
4
|
+
data.tar.gz: f0f88cdbbf0e65a8eadddf0e390d91f3c1a5f4c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0686581b72dd43ef079e93f8b3336669f50919e5f8adaa5019b198d4ce39b61771584ffcab122640cadbe1bdb372d4745bb4f444ee3d3d799833f2f73215b2f
|
7
|
+
data.tar.gz: 1b11eae674ea31430894a4e4f050e91f2011841a94f72c6b580269f446eab4a5e4baacdda616c70e3b0a889b13fdd8fa51633fec9e936401bd01399f45857ab1
|
data/CHANGELOG.md
CHANGED
data/lib/stockboy/provider.rb
CHANGED
@@ -6,6 +6,8 @@ module Stockboy
|
|
6
6
|
YIELD_ONCE = proc { |output, provider| output << provider }
|
7
7
|
|
8
8
|
attr_reader :base_provider
|
9
|
+
attr_reader :data_size
|
10
|
+
attr_reader :data_time
|
9
11
|
|
10
12
|
def initialize(provider, &yielder)
|
11
13
|
@orig_provider = provider
|
@@ -13,16 +15,20 @@ module Stockboy
|
|
13
15
|
@yielder = yielder || YIELD_ONCE
|
14
16
|
end
|
15
17
|
|
18
|
+
def data?
|
19
|
+
@data_size && @data_size > 0
|
20
|
+
end
|
21
|
+
|
16
22
|
def data
|
17
|
-
|
18
|
-
return nil unless block_given?
|
23
|
+
raise ArgumentError, "expects a block for yielding each data set" unless block_given?
|
19
24
|
each do |nth_provider|
|
20
|
-
yield nth_provider
|
25
|
+
yield fetch_iteration_data(nth_provider)
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
24
29
|
def clear
|
25
30
|
@base_provider = @orig_provider.dup
|
31
|
+
@data_time, @data_size = nil, nil
|
26
32
|
super
|
27
33
|
end
|
28
34
|
|
@@ -59,5 +65,13 @@ module Stockboy
|
|
59
65
|
base_provider.public_send(method, *args, &block)
|
60
66
|
end
|
61
67
|
|
68
|
+
def fetch_iteration_data(provider)
|
69
|
+
if provider.data
|
70
|
+
@data_size = [@data_size, provider.data_size].compact.reduce(&:+)
|
71
|
+
@data_time = [@data_time, provider.data_time].compact.max
|
72
|
+
end
|
73
|
+
provider.data
|
74
|
+
end
|
75
|
+
|
62
76
|
end
|
63
77
|
end
|
data/lib/stockboy/version.rb
CHANGED
data/spec/stockboy/job_spec.rb
CHANGED
@@ -3,12 +3,10 @@ require 'stockboy/provider_repeater'
|
|
3
3
|
|
4
4
|
class PaginatedProviderSubclass < Stockboy::Provider
|
5
5
|
attr_accessor :page
|
6
|
-
def validate
|
7
|
-
|
8
|
-
end
|
9
|
-
def
|
10
|
-
@data = "TEST,DATA,#{page}"
|
11
|
-
end
|
6
|
+
def validate; true end
|
7
|
+
def fetch_data; @data = "TEST,DATA,#{page}" end
|
8
|
+
def data_size; @data && @data.size end
|
9
|
+
def data_time; @data && Time.now end
|
12
10
|
end
|
13
11
|
|
14
12
|
module Stockboy
|
@@ -76,5 +74,35 @@ module Stockboy
|
|
76
74
|
end
|
77
75
|
end
|
78
76
|
|
77
|
+
describe "#data_size" do
|
78
|
+
subject(:repeater) { ProviderRepeater.new(provider) }
|
79
|
+
its(:data_size) { should be_nil }
|
80
|
+
|
81
|
+
context "after iterating" do
|
82
|
+
before { repeater.data do |data| end }
|
83
|
+
its(:data_size) { should be > 0 }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#data_time" do
|
88
|
+
subject(:repeater) { ProviderRepeater.new(provider) }
|
89
|
+
its(:data_time) { should be_nil }
|
90
|
+
|
91
|
+
context "after iterating" do
|
92
|
+
before { repeater.data do |data| end }
|
93
|
+
its(:data_time) { should be_a Time }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#data?" do
|
98
|
+
subject(:repeater) { ProviderRepeater.new(provider) }
|
99
|
+
its(:data?) { should be_nil }
|
100
|
+
|
101
|
+
context "after iterating" do
|
102
|
+
before { repeater.data do |data| end }
|
103
|
+
its(:data?) { should be true }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
79
107
|
end
|
80
108
|
end
|
@@ -7,6 +7,8 @@ class ProviderSubclass < Stockboy::Provider
|
|
7
7
|
end
|
8
8
|
def fetch_data
|
9
9
|
@data = "TEST,DATA"
|
10
|
+
@data_time = Time.now
|
11
|
+
@data_size = @data.size
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
@@ -71,5 +73,36 @@ module Stockboy
|
|
71
73
|
should_not include "@data"
|
72
74
|
end
|
73
75
|
end
|
76
|
+
|
77
|
+
describe "#data_size" do
|
78
|
+
subject(:provider) { ProviderSubclass.new }
|
79
|
+
its(:data_size) { should be_nil }
|
80
|
+
|
81
|
+
context "after fetching" do
|
82
|
+
before { provider.data }
|
83
|
+
its(:data_size) { should be > 0 }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#data_time" do
|
88
|
+
subject(:provider) { ProviderSubclass.new }
|
89
|
+
its(:data_time) { should be_nil }
|
90
|
+
|
91
|
+
context "after iterating" do
|
92
|
+
before { provider.data }
|
93
|
+
its(:data_time) { should be_a Time }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#data?" do
|
98
|
+
subject(:provider) { ProviderSubclass.new }
|
99
|
+
its(:data?) { should be_nil }
|
100
|
+
|
101
|
+
context "after iterating" do
|
102
|
+
before { provider.data }
|
103
|
+
its(:data?) { should be true }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
74
107
|
end
|
75
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stockboy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Vit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|