csb 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +3 -7
- data/CHANGELOG.md +9 -0
- data/README.md +2 -0
- data/csb.gemspec +2 -2
- data/gemfiles/rails60.gemfile +1 -1
- data/gemfiles/rails61.gemfile +1 -1
- 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 +9 -9
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
@@ -15,17 +15,13 @@ jobs:
|
|
15
15
|
strategy:
|
16
16
|
fail-fast: false
|
17
17
|
matrix:
|
18
|
-
ruby: ["
|
19
|
-
gemfile: ["
|
18
|
+
ruby: ["3.0", "3.1", "3.2", "3.3"]
|
19
|
+
gemfile: ["rails61", "rails70"]
|
20
20
|
exclude:
|
21
|
-
- ruby: "2.6"
|
22
|
-
gemfile: "rails70"
|
23
|
-
- ruby: "3.1"
|
24
|
-
gemfile: "rails60"
|
25
21
|
- ruby: "3.1"
|
26
22
|
gemfile: "rails61"
|
27
23
|
steps:
|
28
|
-
- uses: actions/checkout@
|
24
|
+
- uses: actions/checkout@v3
|
29
25
|
|
30
26
|
- name: Set up Ruby
|
31
27
|
uses: ruby/setup-ruby@v1
|
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/csb.gemspec
CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
spec.required_ruby_version = '>=
|
25
|
+
spec.required_ruby_version = '>= 3.0.0'
|
26
26
|
|
27
|
-
spec.add_dependency "rails", ">= 6.0
|
27
|
+
spec.add_dependency "rails", ">= 6.1.0"
|
28
28
|
spec.add_dependency "csv"
|
29
29
|
|
30
30
|
spec.add_development_dependency "bundler", "~> 2.0"
|
data/gemfiles/rails60.gemfile
CHANGED
data/gemfiles/rails61.gemfile
CHANGED
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
|
-
autorequire:
|
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
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 6.0
|
19
|
+
version: 6.1.0
|
20
20
|
type: :runtime
|
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: 6.0
|
26
|
+
version: 6.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: csv
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,7 +116,7 @@ homepage: https://github.com/aki77/csb
|
|
116
116
|
licenses:
|
117
117
|
- MIT
|
118
118
|
metadata: {}
|
119
|
-
post_install_message:
|
119
|
+
post_install_message:
|
120
120
|
rdoc_options: []
|
121
121
|
require_paths:
|
122
122
|
- lib
|
@@ -124,15 +124,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
124
|
requirements:
|
125
125
|
- - ">="
|
126
126
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
127
|
+
version: 3.0.0
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - ">="
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
|
-
rubygems_version: 3.
|
135
|
-
signing_key:
|
134
|
+
rubygems_version: 3.4.10
|
135
|
+
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: A simple and streaming support CSV template engine for Ruby on Rails.
|
138
138
|
test_files: []
|