world_bank_fetcher 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,6 @@ module WorldBankFetcher
|
|
4
4
|
|
5
5
|
def initialize(query)
|
6
6
|
@query = query
|
7
|
-
@results = []
|
8
7
|
end
|
9
8
|
|
10
9
|
def execute!
|
@@ -31,26 +30,21 @@ module WorldBankFetcher
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def fetch_data_query!
|
34
|
-
results =
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
results = query.fetch
|
34
|
+
if query.total > MAXIMUM_BUFFER_SIZE
|
35
|
+
total_queries.times do |i|
|
36
|
+
unless i == 0
|
37
|
+
results.concat query.page(i+1).fetch
|
38
|
+
end
|
39
|
+
end
|
40
|
+
results
|
41
|
+
else
|
42
|
+
results
|
39
43
|
end
|
40
|
-
results
|
41
44
|
end
|
42
45
|
|
43
46
|
def total_queries
|
44
|
-
query.per_page(1).fetch unless query.total
|
45
47
|
(query.total / MAXIMUM_BUFFER_SIZE.to_f).ceil
|
46
48
|
end
|
47
|
-
|
48
|
-
def results=(results)
|
49
|
-
@results = results
|
50
|
-
end
|
51
|
-
|
52
|
-
def results
|
53
|
-
@results
|
54
|
-
end
|
55
49
|
end
|
56
50
|
end
|
@@ -34,17 +34,15 @@ module WorldBankFetcher
|
|
34
34
|
fake_results = scheduler.execute!
|
35
35
|
end
|
36
36
|
|
37
|
-
it "should call
|
38
|
-
query.should_receive(:
|
39
|
-
query.should_receive(:
|
40
|
-
query.should_receive(:total).and_return(DEFAULT_INITIAL_BUFFER_SIZE - 1)
|
37
|
+
it "should only call fetch once if all data received in first fetch" do
|
38
|
+
query.should_receive(:fetch).once.and_return(fake_results)
|
39
|
+
query.should_receive(:total).and_return(MAXIMUM_BUFFER_SIZE - 1)
|
41
40
|
scheduler.execute!
|
42
41
|
end
|
43
42
|
|
44
43
|
it "should call preliminary fetch on query if total is nil, then two full data queries given larger data set" do
|
45
|
-
query.should_receive(:
|
46
|
-
query.
|
47
|
-
query.should_receive(:total).and_return(MAXIMUM_BUFFER_SIZE + 1)
|
44
|
+
query.should_receive(:fetch).twice.and_return(fake_results)
|
45
|
+
query.stub(:total).and_return(MAXIMUM_BUFFER_SIZE + 1)
|
48
46
|
scheduler.execute!
|
49
47
|
end
|
50
48
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: world_bank_fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -83,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
segments:
|
85
85
|
- 0
|
86
|
-
hash:
|
86
|
+
hash: -1337123450392843755
|
87
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
88
|
none: false
|
89
89
|
requirements:
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
segments:
|
94
94
|
- 0
|
95
|
-
hash:
|
95
|
+
hash: -1337123450392843755
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
98
|
rubygems_version: 1.8.24
|