csb 0.2.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4afb6c06ec16d04dbd0f1c134e8dbcff3ea8e6ee70ff36a4f0fcf6d71be2e1a2
4
- data.tar.gz: c9f1b9d3e4fb907e0301ec37c7f6080d497f12020b052ba4aefb4b51e63c2d71
3
+ metadata.gz: abfc516a242c529b3b1726b6846609df41e8f617a9b9ceba69ae02d7b28d4026
4
+ data.tar.gz: d40c9e5d581bad2b10559b41f4935a772943c139432b7ce06837dc88ba65900f
5
5
  SHA512:
6
- metadata.gz: 17a9a7c0bc365515117938e71962c2742d3618bb231e43a3ad8be68161d18f0e0407b14802bcef42f2242279fa7810190f86bad7466ed66389fb487c09e77bed
7
- data.tar.gz: a9770d65df6d056328757ff536bb2292e54c4550d36b551284fba7aeee5b7588967cdc714991c66ea33e49fbf0bb4440e7492d67cd94a773d0c514c8186ef4be
6
+ metadata.gz: d98d4bfa10070f589622deb111c38a90b4eedcd6df222edb7fe4eb52f807b11a3c8d1dd684f92a2c07c21929c687adb632ce65dd9aacdca3bb2a8d7b4a911447
7
+ data.tar.gz: fb3283a59df41d2e0e5adcf26d260dc955d4094357aacd39320291000e84e5fb128d2b81550d5efa5e0d56587474fa8bacd118030cfd77ecfcf53f02c9f0166e
@@ -0,0 +1,47 @@
1
+ name: Build
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+
8
+ jobs:
9
+ rspec:
10
+
11
+ runs-on: ubuntu-latest
12
+ env:
13
+ BUNDLE_JOBS: 4
14
+ BUNDLE_RETRY: 3
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ ruby: [2.6, 2.7]
19
+ gemfile: [
20
+ "gemfiles/rails52.gemfile",
21
+ "gemfiles/rails60.gemfile",
22
+ ]
23
+ steps:
24
+ - name: Install packages
25
+ run: |
26
+ sudo apt update -y
27
+ sudo apt install -y libsqlite3-dev
28
+ - uses: actions/checkout@v2
29
+ - uses: actions/cache@v1
30
+ with:
31
+ path: /home/runner/bundle
32
+ key: bundle-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ hashFiles(matrix.gemfile) }}-${{ hashFiles('**/*.gemspec') }}
33
+ restore-keys: |
34
+ bundle-${{ matrix.ruby }}-${{ matrix.gemfile }}-
35
+ - name: Set up Ruby
36
+ uses: ruby/setup-ruby@v1
37
+ with:
38
+ ruby-version: ${{ matrix.ruby }}
39
+ - name: Install dependencies
40
+ run: |
41
+ bundle config path /home/runner/bundle
42
+ bundle config --global gemfile ${{ matrix.gemfile }}
43
+ bundle install
44
+ bundle update
45
+ bundle clean
46
+ - name: Run rspec
47
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  Gemfile.lock
13
+ /vendor/bundle
@@ -1,3 +1,24 @@
1
+ ## 0.4.0
2
+
3
+ - Csb::Cols#initialize supports block arguments
4
+ - Add Testing Helper
5
+
6
+ ## 0.3.1
7
+
8
+ - Refactor
9
+
10
+ ## 0.3.0
11
+
12
+ - Add ignore_class_names config
13
+
14
+ ## 0.2.4
15
+
16
+ - Clean up rack@2.2.x monkey patch.
17
+
18
+ ## 0.2.3
19
+
20
+ - Fix rack@2.2.x bug https://github.com/rack/rack/issues/1619
21
+
1
22
  ## 0.2.2
2
23
 
3
24
  - Update dependency
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Gem Version](https://badge.fury.io/rb/csb.svg)](https://rubygems.org/gems/csb)
2
+ [![Build](https://github.com/aki77/csb/workflows/Build/badge.svg)](https://github.com/aki77/csb/actions)
3
+
1
4
  # Csb
2
5
 
3
6
  A simple and streaming support CSV template engine for Ruby on Rails.
@@ -56,6 +59,32 @@ csv.build
56
59
  # 2019/06/02,category3,content2,,dummy
57
60
  ```
58
61
 
62
+ ### Testing
63
+
64
+ ```ruby
65
+ # Your view
66
+ csv.items = @articles
67
+ csv.cols = Article.csb_cols
68
+
69
+ # Your Model
70
+ def self.csb_cols
71
+ Csb.cols.new do |cols|
72
+ cols.add('Update date') { |r| I18n.l(r.updated_at.to_date) }
73
+ cols.add('Categories') { |r| r.categories.pluck(:name).join(' ') }
74
+ cols.add('Title', :title)
75
+ end
76
+ end
77
+
78
+ # Your test
79
+ require 'csb/testing'
80
+
81
+ expect(Article.csb_cols.col_pairs(article)).to eq [
82
+ ['Update date', '2020-01-01'],
83
+ ['Categories', 'test rspec'],
84
+ ['Title', 'Testing'],
85
+ ]
86
+ ```
87
+
59
88
  ## Installation
60
89
 
61
90
  Add this line to your application's Gemfile:
@@ -26,6 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "csv"
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 2.0"
29
- spec.add_development_dependency "rake", ">= 12.3.3"
30
- spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "rspec"
31
31
  end
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '5.2.4.3'
4
+
5
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '6.0.3.1'
4
+
5
+ gemspec path: '../'
@@ -20,6 +20,10 @@ module Csb
20
20
  output << CSV.generate_line(cols.headers)
21
21
  items.each do |item|
22
22
  output << CSV.generate_line(cols.values_by_item(item))
23
+ rescue => error
24
+ break if Csb.configuration.ignore_class_names.include?(error.class.name)
25
+
26
+ raise error
23
27
  end
24
28
  output
25
29
  end
@@ -9,6 +9,7 @@ module Csb
9
9
 
10
10
  def initialize
11
11
  @cols = []
12
+ yield(self) if block_given?
12
13
  end
13
14
 
14
15
  def copy!(other)
@@ -32,5 +33,6 @@ module Csb
32
33
  col.value_by_item(item)
33
34
  end
34
35
  end
36
+ alias_method :values, :values_by_item
35
37
  end
36
38
  end
@@ -1,10 +1,11 @@
1
1
  module Csb
2
2
  class Configuration
3
- attr_accessor :utf8_bom, :streaming, :after_streaming_error
3
+ attr_accessor :utf8_bom, :streaming, :after_streaming_error, :ignore_class_names
4
4
 
5
5
  def initialize
6
6
  @utf8_bom = false
7
7
  @streaming = true
8
+ @ignore_class_names = %w[Puma::ConnectionError]
8
9
  end
9
10
  end
10
11
  end
@@ -20,6 +20,10 @@ module Csb
20
20
  if csv.streaming?
21
21
  response.headers['Cache-Control'] = 'no-cache'
22
22
  response.headers['X-Accel-Buffering'] = 'no'
23
+ # SEE: https://github.com/rack/rack/issues/1619
24
+ if Gem::Version.new('2.2.0') <= Gem::Version.new(Rack::RELEASE)
25
+ response.headers['Last-Modified'] = '0'
26
+ end
23
27
  end
24
28
  csv.build
25
29
  RUBY
@@ -1,7 +1,6 @@
1
1
  module Csb
2
- class Template < Builder
3
- attr_accessor :utf8_bom, :filename, :streaming, :items
4
- attr_reader :cols
2
+ class Template
3
+ attr_accessor :utf8_bom, :filename, :streaming, :items, :cols
5
4
 
6
5
  def initialize(utf8_bom:, streaming:)
7
6
  @utf8_bom = utf8_bom
@@ -0,0 +1,7 @@
1
+ module Csb
2
+ class Cols
3
+ def col_pairs(item)
4
+ headers.zip(values(item))
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Csb
2
- VERSION = "0.2.2"
2
+ VERSION = '0.4.0'
3
3
  end
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.2.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aki77
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-21 00:00:00.000000000 Z
11
+ date: 2020-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 12.3.3
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 12.3.3
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '3.0'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3.0'
82
+ version: '0'
83
83
  description: A simple and streaming support CSV template engine for Ruby on Rails.
84
84
  email:
85
85
  - aki77@users.noreply.github.com
@@ -87,6 +87,7 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/workflows/rspec.yml"
90
91
  - ".gitignore"
91
92
  - ".rspec"
92
93
  - ".travis.yml"
@@ -99,6 +100,8 @@ files:
99
100
  - bin/console
100
101
  - bin/setup
101
102
  - csb.gemspec
103
+ - gemfiles/rails52.gemfile
104
+ - gemfiles/rails60.gemfile
102
105
  - lib/csb.rb
103
106
  - lib/csb/builder.rb
104
107
  - lib/csb/col.rb
@@ -107,6 +110,7 @@ files:
107
110
  - lib/csb/handler.rb
108
111
  - lib/csb/railtie.rb
109
112
  - lib/csb/template.rb
113
+ - lib/csb/testing.rb
110
114
  - lib/csb/version.rb
111
115
  homepage: https://github.com/aki77/csb
112
116
  licenses:
@@ -127,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
131
  - !ruby/object:Gem::Version
128
132
  version: '0'
129
133
  requirements: []
130
- rubygems_version: 3.0.3
134
+ rubygems_version: 3.1.2
131
135
  signing_key:
132
136
  specification_version: 4
133
137
  summary: A simple and streaming support CSV template engine for Ruby on Rails.