stream_lines 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +12 -0
- data/.github/workflows/ruby-tests.yml +32 -0
- data/.github/workflows/{ci-tests.yml → style-check.yml} +5 -5
- data/.rubocop.yml +2 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +53 -50
- data/README.md +32 -1
- data/lib/stream_lines/reading/csv.rb +2 -1
- data/lib/stream_lines/version.rb +1 -1
- data/stream_lines.gemspec +2 -1
- metadata +26 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d12669d8a8c0f786d731b6fb98374e4105b483379e6ad9b0cb346a62289c5481
|
4
|
+
data.tar.gz: 67607b92517c8b6151e576258314ed4896344893b1a5160602e018aa0aae7d28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 178c5fc570b8dba9330efcd6493b2437fdbd6ed277e3ec653d7c6e436fcb959fea89110781059e5a6acf3e821fa5cb098afcee35664dbac028469baf3542f5cf
|
7
|
+
data.tar.gz: a9e08b3b01ad37fd2daf0e1e10ed729fb8ceabe0e151c2e147c0d131216bf2f1cca2562240890db816a869fc2c7f8c52618796769b20cb8c92e920b16cf11ff0
|
@@ -0,0 +1,32 @@
|
|
1
|
+
name: Tests (Ruby)
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- '*'
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby_version:
|
17
|
+
- 2.6
|
18
|
+
- 2.7
|
19
|
+
- 3.0
|
20
|
+
- 3.1
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
- name: Set up Ruby
|
24
|
+
uses: ruby/setup-ruby@v1
|
25
|
+
with:
|
26
|
+
ruby-version: ${{ matrix.ruby_version }}
|
27
|
+
- name: Ruby version
|
28
|
+
run: ruby -v
|
29
|
+
- name: Install dependencies
|
30
|
+
run: bundle install
|
31
|
+
- name: Run tests
|
32
|
+
run: bundle exec rake
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
6
|
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
7
|
|
8
|
-
name:
|
8
|
+
name: Style Check
|
9
9
|
|
10
10
|
on:
|
11
11
|
push:
|
@@ -16,15 +16,15 @@ on:
|
|
16
16
|
- '*'
|
17
17
|
|
18
18
|
jobs:
|
19
|
-
|
19
|
+
rubocop:
|
20
20
|
runs-on: ubuntu-latest
|
21
21
|
steps:
|
22
22
|
- uses: actions/checkout@v2
|
23
23
|
- name: Set up Ruby
|
24
24
|
uses: ruby/setup-ruby@v1
|
25
25
|
with:
|
26
|
-
ruby-version:
|
26
|
+
ruby-version: 3.0
|
27
27
|
- name: Install dependencies
|
28
28
|
run: bundle install
|
29
|
-
- name: Run
|
30
|
-
run: bundle exec
|
29
|
+
- name: Run Rubocop
|
30
|
+
run: bundle exec rubocop -D
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.2
|
data/Gemfile.lock
CHANGED
@@ -1,84 +1,85 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stream_lines (0.4.
|
4
|
+
stream_lines (0.4.1)
|
5
5
|
httparty (~> 0.14)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
addressable (2.
|
10
|
+
addressable (2.8.0)
|
11
11
|
public_suffix (>= 2.0.2, < 5.0)
|
12
|
-
ast (2.4.
|
13
|
-
awesome_print (1.
|
12
|
+
ast (2.4.2)
|
13
|
+
awesome_print (1.9.2)
|
14
14
|
backports (3.17.2)
|
15
|
-
bundler-audit (0.
|
15
|
+
bundler-audit (0.9.0.1)
|
16
16
|
bundler (>= 1.2.0, < 3)
|
17
|
-
thor (
|
17
|
+
thor (~> 1.0)
|
18
18
|
bundler-gem_version_tasks (0.2.1)
|
19
19
|
byebug (11.1.3)
|
20
20
|
charlock_holmes (0.7.7)
|
21
|
-
crack (0.4.
|
22
|
-
|
23
|
-
diff-lcs (1.
|
24
|
-
docile (1.3.
|
25
|
-
ffi (1.13.
|
26
|
-
get_process_mem (0.2.
|
21
|
+
crack (0.4.5)
|
22
|
+
rexml
|
23
|
+
diff-lcs (1.5.0)
|
24
|
+
docile (1.3.4)
|
25
|
+
ffi (1.13.1)
|
26
|
+
get_process_mem (0.2.7)
|
27
27
|
ffi (~> 1.0)
|
28
28
|
hashdiff (1.0.1)
|
29
|
-
httparty (0.
|
29
|
+
httparty (0.20.0)
|
30
30
|
mime-types (~> 3.0)
|
31
31
|
multi_xml (>= 0.5.2)
|
32
|
-
memory_profiler (0.
|
32
|
+
memory_profiler (1.0.0)
|
33
33
|
mime-types (3.3.1)
|
34
34
|
mime-types-data (~> 3.2015)
|
35
|
-
mime-types-data (3.
|
35
|
+
mime-types-data (3.2021.0901)
|
36
36
|
multi_json (1.14.1)
|
37
37
|
multi_xml (0.6.0)
|
38
38
|
mustermann (1.1.1)
|
39
39
|
ruby2_keywords (~> 0.0.1)
|
40
|
-
parallel (1.
|
41
|
-
parser (
|
40
|
+
parallel (1.22.1)
|
41
|
+
parser (3.1.1.0)
|
42
42
|
ast (~> 2.4.1)
|
43
|
-
public_suffix (4.0.
|
43
|
+
public_suffix (4.0.6)
|
44
44
|
rack (2.2.3)
|
45
45
|
rack-protection (2.0.8.1)
|
46
46
|
rack
|
47
|
-
rainbow (3.
|
48
|
-
rake (13.0.
|
49
|
-
regexp_parser (
|
50
|
-
rexml (3.2.
|
51
|
-
rspec (3.
|
52
|
-
rspec-core (~> 3.
|
53
|
-
rspec-expectations (~> 3.
|
54
|
-
rspec-mocks (~> 3.
|
55
|
-
rspec-core (3.
|
56
|
-
rspec-support (~> 3.
|
57
|
-
rspec-expectations (3.
|
47
|
+
rainbow (3.1.1)
|
48
|
+
rake (13.0.6)
|
49
|
+
regexp_parser (2.3.0)
|
50
|
+
rexml (3.2.5)
|
51
|
+
rspec (3.11.0)
|
52
|
+
rspec-core (~> 3.11.0)
|
53
|
+
rspec-expectations (~> 3.11.0)
|
54
|
+
rspec-mocks (~> 3.11.0)
|
55
|
+
rspec-core (3.11.0)
|
56
|
+
rspec-support (~> 3.11.0)
|
57
|
+
rspec-expectations (3.11.0)
|
58
58
|
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
-
rspec-support (~> 3.
|
60
|
-
rspec-mocks (3.
|
59
|
+
rspec-support (~> 3.11.0)
|
60
|
+
rspec-mocks (3.11.0)
|
61
61
|
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
-
rspec-support (~> 3.
|
63
|
-
rspec-support (3.
|
64
|
-
rubocop (
|
62
|
+
rspec-support (~> 3.11.0)
|
63
|
+
rspec-support (3.11.0)
|
64
|
+
rubocop (1.27.0)
|
65
65
|
parallel (~> 1.10)
|
66
|
-
parser (>=
|
66
|
+
parser (>= 3.1.0.0)
|
67
67
|
rainbow (>= 2.2.2, < 4.0)
|
68
|
-
regexp_parser (>= 1.
|
68
|
+
regexp_parser (>= 1.8, < 3.0)
|
69
69
|
rexml
|
70
|
-
rubocop-ast (>=
|
70
|
+
rubocop-ast (>= 1.16.0, < 2.0)
|
71
71
|
ruby-progressbar (~> 1.7)
|
72
|
-
unicode-display_width (>= 1.4.0, <
|
73
|
-
rubocop-ast (
|
74
|
-
parser (>=
|
75
|
-
ruby-progressbar (1.
|
72
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
73
|
+
rubocop-ast (1.17.0)
|
74
|
+
parser (>= 3.1.1.0)
|
75
|
+
ruby-progressbar (1.11.0)
|
76
76
|
ruby2_keywords (0.0.2)
|
77
|
-
|
78
|
-
simplecov (0.18.5)
|
77
|
+
simplecov (0.21.2)
|
79
78
|
docile (~> 1.1)
|
80
79
|
simplecov-html (~> 0.11)
|
81
|
-
|
80
|
+
simplecov_json_formatter (~> 0.1)
|
81
|
+
simplecov-html (0.12.3)
|
82
|
+
simplecov_json_formatter (0.1.2)
|
82
83
|
sinatra (2.0.8.1)
|
83
84
|
mustermann (~> 1.0)
|
84
85
|
rack (~> 2.0)
|
@@ -91,13 +92,14 @@ GEM
|
|
91
92
|
rack-protection (= 2.0.8.1)
|
92
93
|
sinatra (= 2.0.8.1)
|
93
94
|
tilt (~> 2.0)
|
94
|
-
thor (1.0
|
95
|
+
thor (1.1.0)
|
95
96
|
tilt (2.0.10)
|
96
|
-
unicode-display_width (1.
|
97
|
-
webmock (3.
|
98
|
-
addressable (>= 2.
|
97
|
+
unicode-display_width (2.1.0)
|
98
|
+
webmock (3.14.0)
|
99
|
+
addressable (>= 2.8.0)
|
99
100
|
crack (>= 0.3.2)
|
100
101
|
hashdiff (>= 0.4.0, < 2.0.0)
|
102
|
+
webrick (1.7.0)
|
101
103
|
|
102
104
|
PLATFORMS
|
103
105
|
ruby
|
@@ -113,12 +115,13 @@ DEPENDENCIES
|
|
113
115
|
memory_profiler
|
114
116
|
rake (~> 13.0)
|
115
117
|
rspec (~> 3.0)
|
116
|
-
rubocop (~>
|
118
|
+
rubocop (~> 1.27.0)
|
117
119
|
simplecov (~> 0.17)
|
118
120
|
sinatra (~> 2.0)
|
119
121
|
sinatra-contrib (~> 2.0)
|
120
122
|
stream_lines!
|
121
123
|
webmock (~> 3.0)
|
124
|
+
webrick (~> 1.7)
|
122
125
|
|
123
126
|
BUNDLED WITH
|
124
|
-
2.
|
127
|
+
2.3.11
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# StreamLines
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/stream_lines.svg)](https://badge.fury.io/rb/stream_lines)
|
4
|
-
![](https://github.com/jdlubrano/stream_lines/workflows/
|
4
|
+
[![Tests (Ruby)](https://github.com/jdlubrano/stream_lines/actions/workflows/ruby-tests.yml/badge.svg)](https://github.com/jdlubrano/stream_lines/actions/workflows/ruby-tests.yml)
|
5
5
|
|
6
6
|
An API for streaming files from remote locations one line at a time.
|
7
7
|
|
@@ -55,6 +55,37 @@ stream.each_slice(100) do |lines|
|
|
55
55
|
end
|
56
56
|
```
|
57
57
|
|
58
|
+
##### Caveats
|
59
|
+
|
60
|
+
This library strives to provide streamed data via an `Enumerable` interface.
|
61
|
+
In order to be memory-efficient, however, each time the stream is iterated over,
|
62
|
+
a new GET request is made to fetch the data from its remote URL. For example,
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
url = 'https://my.remote.file/file.txt'
|
66
|
+
stream = StreamLines::Reading::Stream.new(url)
|
67
|
+
do_something_with_first_row(stream.first) # GET request made
|
68
|
+
|
69
|
+
stream.each do |line| # same GET request made
|
70
|
+
# Do something with the line of data (the line will be a String)
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
makes two GET requests. The call to `first` makes a GET request to fetch
|
75
|
+
the first row of data. The subsequent call to `each` makes the same GET
|
76
|
+
request. To avoid unnecessary requests, I recommend a slightly different
|
77
|
+
approach, which may not be intuitive but does make only one network request:
|
78
|
+
|
79
|
+
```
|
80
|
+
url = 'https://my.remote.file/file.txt'
|
81
|
+
stream = StreamLines::Reading::Stream.new(url)
|
82
|
+
|
83
|
+
stream.each_with_index do |line, i|
|
84
|
+
do_something_with_first_row(line) if i.zero?
|
85
|
+
# Do something with the line of data (the line will be a String)
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
58
89
|
##### CSVs
|
59
90
|
|
60
91
|
This gem provides first-class support for streaming CSVs from a remote URL.
|
@@ -23,6 +23,7 @@ module StreamLines
|
|
23
23
|
def initialize(url, **csv_options)
|
24
24
|
@url = url
|
25
25
|
@csv_options = accepted_csv_options(csv_options)
|
26
|
+
@first_row_headers = @csv_options[:headers] == true
|
26
27
|
|
27
28
|
encoding = @csv_options[:encoding] || Encoding.default_external
|
28
29
|
@stream = Stream.new(url, encoding: encoding)
|
@@ -41,7 +42,7 @@ module StreamLines
|
|
41
42
|
attr_reader :url
|
42
43
|
|
43
44
|
def first_row_headers?
|
44
|
-
@
|
45
|
+
@first_row_headers
|
45
46
|
end
|
46
47
|
|
47
48
|
def assign_first_row_headers(first_line)
|
data/lib/stream_lines/version.rb
CHANGED
data/stream_lines.gemspec
CHANGED
@@ -38,9 +38,10 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_development_dependency 'memory_profiler'
|
39
39
|
spec.add_development_dependency 'rake', '~> 13.0'
|
40
40
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
41
|
-
spec.add_development_dependency 'rubocop', '~>
|
41
|
+
spec.add_development_dependency 'rubocop', '~> 1.27.0'
|
42
42
|
spec.add_development_dependency 'simplecov', '~> 0.17'
|
43
43
|
spec.add_development_dependency 'sinatra', '~> 2.0'
|
44
44
|
spec.add_development_dependency 'sinatra-contrib', '~> 2.0'
|
45
|
+
spec.add_development_dependency 'webrick', '~> 1.7'
|
45
46
|
spec.add_development_dependency 'webmock', '~> 3.0'
|
46
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stream_lines
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Lubrano
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -170,14 +170,14 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
173
|
+
version: 1.27.0
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
180
|
+
version: 1.27.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: simplecov
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '2.0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: webrick
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '1.7'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '1.7'
|
223
237
|
- !ruby/object:Gem::Dependency
|
224
238
|
name: webmock
|
225
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -234,14 +248,16 @@ dependencies:
|
|
234
248
|
- - "~>"
|
235
249
|
- !ruby/object:Gem::Version
|
236
250
|
version: '3.0'
|
237
|
-
description:
|
251
|
+
description:
|
238
252
|
email:
|
239
253
|
- joel.lubrano@gmail.com
|
240
254
|
executables: []
|
241
255
|
extensions: []
|
242
256
|
extra_rdoc_files: []
|
243
257
|
files:
|
244
|
-
- ".github/
|
258
|
+
- ".github/dependabot.yml"
|
259
|
+
- ".github/workflows/ruby-tests.yml"
|
260
|
+
- ".github/workflows/style-check.yml"
|
245
261
|
- ".gitignore"
|
246
262
|
- ".rspec"
|
247
263
|
- ".rubocop.yml"
|
@@ -270,7 +286,7 @@ metadata:
|
|
270
286
|
homepage_uri: https://github.com/jdlubrano/stream_lines
|
271
287
|
source_code_uri: https://github.com/jdlubrano/stream_lines
|
272
288
|
changelog_uri: https://github.com/jdlubrano/stream_lines/releases
|
273
|
-
post_install_message:
|
289
|
+
post_install_message:
|
274
290
|
rdoc_options: []
|
275
291
|
require_paths:
|
276
292
|
- lib
|
@@ -285,8 +301,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
285
301
|
- !ruby/object:Gem::Version
|
286
302
|
version: '0'
|
287
303
|
requirements: []
|
288
|
-
rubygems_version: 3.
|
289
|
-
signing_key:
|
304
|
+
rubygems_version: 3.3.7
|
305
|
+
signing_key:
|
290
306
|
specification_version: 4
|
291
307
|
summary: A utility to stream lines of a file over HTTP
|
292
308
|
test_files: []
|