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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 112b4e9e1be4b25eb7f4c7532802d049bda588c2
4
- data.tar.gz: 3e8b45cdb2bf498eae916d0acdb4428c340889f0
3
+ metadata.gz: 90e9bfd03d069c571ffd1e6e03dd018cf477289c
4
+ data.tar.gz: f0f88cdbbf0e65a8eadddf0e390d91f3c1a5f4c4
5
5
  SHA512:
6
- metadata.gz: 5d5d2f526f5f09d621cd17aaff3cc845a4dbfef7a0ca137dd740bb402ceb35a84ae089eaa5e518cf175c848fb52a1a7ed46a9d0b5b04e37292bdd36dd5502880
7
- data.tar.gz: 288708c22880493da3ed6d7450ca5da69ed54597ab6ee0b4dadd7b22dfe35535ef34ebcb5f6357dde4b858778dc03d435d0a331761f1e573418be33aa2893641
6
+ metadata.gz: d0686581b72dd43ef079e93f8b3336669f50919e5f8adaa5019b198d4ce39b61771584ffcab122640cadbe1bdb372d4745bb4f444ee3d3d799833f2f73215b2f
7
+ data.tar.gz: 1b11eae674ea31430894a4e4f050e91f2011841a94f72c6b580269f446eab4a5e4baacdda616c70e3b0a889b13fdd8fa51633fec9e936401bd01399f45857ab1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0 / 2014-04-02
4
+
5
+ * [ENHANCEMENT] Expose `data_time` and `data_size` in repeater
6
+ * [ENHANCEMENT] Expose `data?` method to check for loaded data
7
+
3
8
  ## 0.7.2 / 2014-04-02
4
9
 
5
10
  * [BUGFIX] Require missing repeater class in DSL
@@ -81,6 +81,10 @@ module Stockboy
81
81
  @data
82
82
  end
83
83
 
84
+ def data?
85
+ @data_size && @data_size > 0
86
+ end
87
+
84
88
  # Reset received data
85
89
  #
86
90
  # @return [Boolean] Always true
@@ -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
- # return base_provider.data unless block_given?
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.data
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
@@ -1,3 +1,3 @@
1
1
  module Stockboy
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -10,6 +10,8 @@ class TestProvider
10
10
  def clear
11
11
  @data = nil
12
12
  end
13
+ def data_size; @data && @data.size end
14
+ def data_time; @data && Time.now end
13
15
  end
14
16
 
15
17
  class TestReader
@@ -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
- true
8
- end
9
- def fetch_data
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.7.2
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-02 00:00:00.000000000 Z
11
+ date: 2014-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake