csb 0.7.0 → 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/.github/workflows/rspec.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/lib/csb/builder.rb +5 -4
- data/lib/csb/configuration.rb +2 -1
- data/lib/csb/handler.rb +1 -0
- data/lib/csb/template.rb +5 -4
- data/lib/csb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65631a79f4d83eb7a03b39ec88084daf60fb32249894116d4362c009bee3d9ff
|
4
|
+
data.tar.gz: '04825902e66e259ea488c97884f9b0bb4540d0ec1f2b2d58e087fc84b3491516'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bed968513f2be918b5c0fcefa1d711bc86858c118fa2561c5b5ec80d36de41460712ff82079ca006338d2ef2ce64c87b66a1252681aea964c80f2bf3b4ea6d6
|
7
|
+
data.tar.gz: 567168271617cd1f96665dec7c9d5acd7e9f1dfb4ce017fefd95ceccc4ff40cbb8a94b58ca4fb989af7299d98abe2d1ca5f8ca8c638eb0d86d7a347d4f38c42a
|
data/.github/workflows/rspec.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -37,6 +37,7 @@ csv.items = @reports
|
|
37
37
|
|
38
38
|
# csv.filename = "reports_#{Time.current.to_i}.csv"
|
39
39
|
# csv.streaming = false
|
40
|
+
# csv.csv_options = { col_sep: "\t" }
|
40
41
|
|
41
42
|
csv.cols.add('Update date') { |r| l(r.updated_at.to_date) }
|
42
43
|
csv.cols.add('Categories') { |r| r.categories.pluck(:name).join(' ') }
|
@@ -130,6 +131,7 @@ In `config/initializers/csb.rb`, you can configure the following values.
|
|
130
131
|
Csb.configure do |config|
|
131
132
|
config.utf8_bom = true # default: false
|
132
133
|
config.streaming = false # default: true
|
134
|
+
config.csv_options = { col_sep: "\t" } # default: {}
|
133
135
|
config.after_streaming_error = ->(error) do # default: nil
|
134
136
|
Rails.logger.error(error)
|
135
137
|
Bugsnag.notify(error)
|
data/lib/csb/builder.rb
CHANGED
@@ -5,21 +5,22 @@ module Csb
|
|
5
5
|
class Builder
|
6
6
|
UTF8_BOM = "\xEF\xBB\xBF".freeze
|
7
7
|
|
8
|
-
attr_reader :output, :utf8_bom, :items, :cols
|
8
|
+
attr_reader :output, :utf8_bom, :items, :cols, :csv_options
|
9
9
|
attr_accessor :items
|
10
10
|
|
11
|
-
def initialize(output = '', items: [], utf8_bom: false)
|
11
|
+
def initialize(output = '', items: [], utf8_bom: false, csv_options: {})
|
12
12
|
@output = output
|
13
13
|
@utf8_bom = utf8_bom
|
14
14
|
@cols = Cols.new
|
15
15
|
@items = items
|
16
|
+
@csv_options = csv_options
|
16
17
|
end
|
17
18
|
|
18
19
|
def build
|
19
20
|
output << UTF8_BOM if utf8_bom
|
20
|
-
output << CSV.generate_line(cols.headers)
|
21
|
+
output << CSV.generate_line(cols.headers, **csv_options)
|
21
22
|
items.each do |item|
|
22
|
-
output << CSV.generate_line(cols.values_by_item(item))
|
23
|
+
output << CSV.generate_line(cols.values_by_item(item), **csv_options)
|
23
24
|
rescue => error
|
24
25
|
break if Csb.configuration.ignore_class_names.include?(error.class.name)
|
25
26
|
|
data/lib/csb/configuration.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Csb
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :utf8_bom, :streaming, :after_streaming_error, :ignore_class_names
|
3
|
+
attr_accessor :utf8_bom, :streaming, :after_streaming_error, :ignore_class_names, :csv_options
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@utf8_bom = false
|
7
7
|
@streaming = true
|
8
|
+
@csv_options = {}
|
8
9
|
@ignore_class_names = %w[Puma::ConnectionError]
|
9
10
|
end
|
10
11
|
end
|
data/lib/csb/handler.rb
CHANGED
@@ -14,6 +14,7 @@ module Csb
|
|
14
14
|
csv = ::Csb::Template.new(
|
15
15
|
utf8_bom: ::Csb.configuration.utf8_bom,
|
16
16
|
streaming: ::Csb.configuration.streaming,
|
17
|
+
csv_options: ::Csb.configuration.csv_options,
|
17
18
|
)
|
18
19
|
#{source}
|
19
20
|
controller.send(:send_file_headers!, type: 'text/csv', filename: csv.filename)
|
data/lib/csb/template.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Csb
|
2
2
|
class Template
|
3
|
-
attr_accessor :utf8_bom, :filename, :streaming, :items, :cols
|
3
|
+
attr_accessor :utf8_bom, :filename, :streaming, :items, :cols, :csv_options
|
4
4
|
|
5
|
-
def initialize(utf8_bom:, streaming:)
|
5
|
+
def initialize(utf8_bom:, streaming:, csv_options:)
|
6
6
|
@utf8_bom = utf8_bom
|
7
7
|
@streaming = streaming
|
8
|
+
@csv_options = csv_options
|
8
9
|
@cols = Cols.new
|
9
10
|
@items = []
|
10
11
|
end
|
@@ -20,7 +21,7 @@ module Csb
|
|
20
21
|
private
|
21
22
|
|
22
23
|
def build_string
|
23
|
-
builder = Builder.new(utf8_bom: utf8_bom, items: items)
|
24
|
+
builder = Builder.new(utf8_bom: utf8_bom, items: items, csv_options: csv_options)
|
24
25
|
builder.cols.copy!(cols)
|
25
26
|
builder.build
|
26
27
|
end
|
@@ -28,7 +29,7 @@ module Csb
|
|
28
29
|
def build_enumerator
|
29
30
|
Enumerator.new do |y|
|
30
31
|
begin
|
31
|
-
builder = Builder.new(y, utf8_bom: utf8_bom, items: items)
|
32
|
+
builder = Builder.new(y, utf8_bom: utf8_bom, items: items, csv_options: csv_options)
|
32
33
|
builder.cols.copy!(cols)
|
33
34
|
builder.build
|
34
35
|
rescue => error
|
data/lib/csb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aki77
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|