loady 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/loady.rb +6 -4
- data/lib/loady/attribute_array.rb +2 -2
- data/lib/loady/csv_loader.rb +13 -11
- data/lib/loady/memory_logger.rb +2 -0
- data/lib/loady/version.rb +3 -1
- metadata +14 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f3cbef0a89c61259ad21fb1a9b7b1567b7e109cea5f6c9ea28ade4d86f898165
|
4
|
+
data.tar.gz: befe698be1e117b169c47cf0d54b8e44c68f92a5097c57bfa3a8843f147f5547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 732c36b0d0a5c3f74ecf03ccf42c279b9a1c0f63bff6f9c88b93a6bc90bf4856b45f5e44dfe2c838e83cef1ff8430fa00366887ba3108e5823f07a0cc82a5863
|
7
|
+
data.tar.gz: d32630555756986ffd055704b47351955421214dc6424ec60e3c17b738af6896c9e49fd1e28cf37163940bcb5263e84a5873153718504d86dbcc0da9c25b774e
|
data/lib/loady.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "loady/attribute_array"
|
4
|
+
require "loady/csv_loader"
|
5
|
+
require "loady/memory_logger"
|
4
6
|
|
5
7
|
module Loady
|
6
8
|
def read(*args, &block)
|
7
9
|
Loady::CsvLoader.new.read(*args, &block)
|
8
10
|
end
|
9
|
-
|
11
|
+
|
10
12
|
alias csv read
|
11
13
|
|
12
14
|
module_function :read, :csv
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Loady
|
2
4
|
class AttributeArray < Array
|
3
|
-
|
4
5
|
# usage:
|
5
6
|
# aa = Loady::AttributeArray.new(['john', 'doe'])
|
6
7
|
# aa.to_attributes([:first, :last])
|
@@ -20,6 +21,5 @@ module Loady
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
23
|
-
|
24
24
|
end
|
25
25
|
end
|
data/lib/loady/csv_loader.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "csv"
|
4
|
+
require "logger"
|
3
5
|
|
4
6
|
module Loady
|
5
7
|
class CsvLoader
|
@@ -19,12 +21,12 @@ module Loady
|
|
19
21
|
options[:headers] ||= options.delete(:skip_first_row)
|
20
22
|
|
21
23
|
CSV.foreach(filename, options) do |line|
|
22
|
-
readline line,
|
24
|
+
readline line, &block
|
23
25
|
end
|
24
|
-
@logger.info "Finished. Loaded #{
|
25
|
-
rescue CSV::MalformedCSVError =>
|
26
|
-
@logger.error
|
27
|
-
@logger.error "Stopped Loading after #{
|
26
|
+
@logger.info "Finished. Loaded #{@success} rows. #{@warning} skipped rows."
|
27
|
+
rescue CSV::MalformedCSVError => e
|
28
|
+
@logger.error e.message
|
29
|
+
@logger.error "Stopped Loading after #{@success} rows. #{@warning} skipped rows."
|
28
30
|
end
|
29
31
|
|
30
32
|
class << self
|
@@ -33,9 +35,9 @@ module Loady
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
|
38
|
+
private
|
37
39
|
|
38
|
-
def readline(line
|
40
|
+
def readline(line)
|
39
41
|
@line_number += 1
|
40
42
|
row = if line.respond_to?(:to_hash)
|
41
43
|
AttributeArray.new(line.to_hash.values)
|
@@ -47,9 +49,9 @@ module Loady
|
|
47
49
|
yield row
|
48
50
|
@success += 1
|
49
51
|
end
|
50
|
-
rescue
|
52
|
+
rescue StandardError => e
|
51
53
|
@warning += 1
|
52
|
-
@logger.warn "#{
|
54
|
+
@logger.warn "#{e.to_s.gsub('line 1', "line #{@line_number}")}\n#{line}"
|
53
55
|
end
|
54
56
|
|
55
57
|
def default_logger
|
data/lib/loady/memory_logger.rb
CHANGED
data/lib/loady/version.rb
CHANGED
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loady
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tee Parham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: minitest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: mocha
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '12.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '12.0'
|
55
55
|
description: File loader with simple logging
|
56
56
|
email:
|
57
57
|
- tee@neighborland.com
|
@@ -66,7 +66,7 @@ files:
|
|
66
66
|
- lib/loady/csv_loader.rb
|
67
67
|
- lib/loady/memory_logger.rb
|
68
68
|
- lib/loady/version.rb
|
69
|
-
homepage:
|
69
|
+
homepage: https://github.com/teeparham/loady
|
70
70
|
licenses:
|
71
71
|
- MIT
|
72
72
|
metadata: {}
|
@@ -78,17 +78,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
81
|
+
version: 2.4.0
|
82
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
84
|
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
|
-
|
89
|
-
rubygems_version: 2.5.1
|
88
|
+
rubygems_version: 3.0.3
|
90
89
|
signing_key:
|
91
90
|
specification_version: 4
|
92
91
|
summary: File loader with simple logging
|
93
92
|
test_files: []
|
94
|
-
has_rdoc:
|