csb 0.2.4 → 0.5.1

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: 03f660277b1cd9d2d49c1ba8c93ecbbb4853b896927795ea6f6224eedf040344
4
- data.tar.gz: 06dc9496068e647f38b028de49343af19c9114e92658d0c0a476fcb992c53755
3
+ metadata.gz: f2301a29400774ab62d1f107853554a59718284eea27e1040ca2d7c6109fceff
4
+ data.tar.gz: 56ebda4dc560f15de5b26eca01741b97164b99e96dc92c0af5b822a1c3a4e8b4
5
5
  SHA512:
6
- metadata.gz: 88ab7dcc5d3b9385f6d7b429cf4f47aae94f0a6bca8b1f1f6744743a5a823d627ae1d6ecef138b9ac3e4aced2eb899b0dd29a988a3e88488b848cd99df5db02d
7
- data.tar.gz: 1bb975774c0aa67a666fea8902738d5652302d5d93d4f4b16542f96d5027bf09657e5f7bb0bde0ffa5a146585179707da76fd42f0862cd394d0620f06bd2a4c6
6
+ metadata.gz: 9c484f8f54f49c2d0f88832017ce9c96c3a3306da56535fbcc6c6320ae44c37ebf4babbfb6be38064dc35b38e85a1dfee5f49dafd9a28c9427496433bed0b73d
7
+ data.tar.gz: 75798c786ce777530dfd6ebc2c7006d66079517d1b4e03e096895c5baf40a863c3e7a65d6083f1c32863915c6d8f7a1abe9ccfb19f7aa719cf6ec6b99189d09a
@@ -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/rails61.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,5 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  Gemfile.lock
13
+ /vendor/bundle
14
+ .vscode/settings.json
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## 0.5.1
2
+
3
+ - Update dependency
4
+
5
+ ## 0.5.0
6
+
7
+ - Add `as_table` testing helper
8
+
9
+ ## 0.4.0
10
+
11
+ - Csb::Cols#initialize supports block arguments
12
+ - Add Testing Helper
13
+
14
+ ## 0.3.1
15
+
16
+ - Refactor
17
+
18
+ ## 0.3.0
19
+
20
+ - Add ignore_class_names config
21
+
1
22
  ## 0.2.4
2
23
 
3
24
  - Clean up rack@2.2.x monkey patch.
data/README.md CHANGED
@@ -1,7 +1,17 @@
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.
4
7
 
8
+ ## Features
9
+
10
+ - Support for streaming downloads
11
+ - Output in UTF-8 with BOM
12
+ - Readable code
13
+ - High testability
14
+
5
15
  ## Usage
6
16
 
7
17
  ### Template handler
@@ -18,9 +28,13 @@ In app/views/reports/index.csv.csb:
18
28
 
19
29
  ```ruby
20
30
  csv.items = @reports
31
+
21
32
  # When there are many records
22
33
  # csv.items = @reports.find_each
23
34
 
35
+ # When there are many records with decorator
36
+ # csv.items = @reports.find_each.lazy.map(&:decorate)
37
+
24
38
  # csv.filename = "reports_#{Time.current.to_i}.csv"
25
39
  # csv.streaming = false
26
40
 
@@ -56,6 +70,38 @@ csv.build
56
70
  # 2019/06/02,category3,content2,,dummy
57
71
  ```
58
72
 
73
+ ### Testing
74
+
75
+ ```ruby
76
+ # Your view
77
+ csv.items = @articles
78
+ csv.cols = Article.csb_cols
79
+
80
+ # Your Model
81
+ def self.csb_cols
82
+ Csb::Cols.new do |cols|
83
+ cols.add('Update date') { |r| I18n.l(r.updated_at.to_date) }
84
+ cols.add('Categories') { |r| r.categories.pluck(:name).join(' ') }
85
+ cols.add('Title', :title)
86
+ end
87
+ end
88
+
89
+ # Your test
90
+ require 'csb/testing'
91
+
92
+ expect(Article.csb_cols.col_pairs(article)).to eq [
93
+ ['Update date', '2020-01-01'],
94
+ ['Categories', 'test rspec'],
95
+ ['Title', 'Testing'],
96
+ ]
97
+
98
+ expect(Article.csb_cols.as_table(articles)).to eq [
99
+ ['Update date', 'Categories', 'Title'],
100
+ ['2020-01-01', 'test rspec', 'Testing'],
101
+ ['2020-02-01', 'rails gem', 'Rails 6.2'],
102
+ ]
103
+ ```
104
+
59
105
  ## Installation
60
106
 
61
107
  Add this line to your application's Gemfile:
data/csb.gemspec CHANGED
@@ -22,10 +22,10 @@ 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.add_dependency "rails", ">= 5.2.4.2"
25
+ spec.add_dependency "rails", ">= 5.2.4.6"
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.6'
4
+
5
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '6.1.3.2'
4
+
5
+ gemspec path: '../'
data/lib/csb/builder.rb CHANGED
@@ -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
data/lib/csb/cols.rb CHANGED
@@ -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
data/lib/csb/template.rb CHANGED
@@ -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,11 @@
1
+ module Csb
2
+ class Cols
3
+ def col_pairs(item)
4
+ headers.zip(values(item))
5
+ end
6
+
7
+ def as_table(items)
8
+ [headers] + items.map { |item| values(item) }
9
+ end
10
+ end
11
+ end
data/lib/csb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Csb
2
- VERSION = '0.2.4'
2
+ VERSION = '0.5.1'
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.4
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - aki77
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-27 00:00:00.000000000 Z
11
+ date: 2021-05-30 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: 5.2.4.2
19
+ version: 5.2.4.6
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: 5.2.4.2
26
+ version: 5.2.4.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: csv
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -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/rails61.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.