csvbuilder-dynamic-columns-exporter 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d6adf64db2e5a0d9c8dc5fb555489ff195bd00c3cebba5736a0ea6fcfb37b11
4
- data.tar.gz: f084c0dc4f1b0df1547e47d7ff285ab7ab597e6f4838d0a926645e09a9a8da61
3
+ metadata.gz: 213815125b6c74652b53bdce18b4fac186feef9668568612509ea63f05842df0
4
+ data.tar.gz: ba70e3d2daaf49b7a6a03a75906c9292eda8615c1eb23b928c96fa39a8344762
5
5
  SHA512:
6
- metadata.gz: 32a3f92953ef63f35d3b30f88d64c72dfba217077e6fb5ffd51ef9d32695098aeb42925acb0fa7e3bbd8336d4691b15d10113a751a8a213d1aa948a8c9823806
7
- data.tar.gz: 2349dcb6730b77a227f3e6340ffb7b2e753bb2f7d880d8f4fb2b3ad678d69bf1e402c0b059f56e805d3ddc353b38a88430b5c76a0c912404b8507c5b68694970
6
+ metadata.gz: 1f1d33dca1976f18350c035cc954c375f73ffc27a5099371a0c0923b1b958ea65708eb1214f9f84cdb8bf5dbc21f09c523bbf48b122cc93d478bc9b4bcd487ce
7
+ data.tar.gz: a59f949990ab6d0e87531fb590192cd66166622b00a331a386b9129f429cff93f8f37ca2fffaf744ff5f09e63dfbd69042a0e63f567e773cbf52dd4b612243ce
data/.rubocop.yml CHANGED
@@ -1,13 +1,13 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
- require:
3
+ plugins:
4
4
  - rubocop-performance
5
5
  - rubocop-rake
6
6
  - rubocop-rspec
7
7
 
8
8
  AllCops:
9
9
  NewCops: enable
10
- TargetRubyVersion: 2.6
10
+ TargetRubyVersion: 3.4
11
11
 
12
12
  Style/StringLiterals:
13
13
  Enabled: true
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-12-23 11:40:53 UTC using RuboCop version 1.41.1.
3
+ # on 2025-02-27 05:00:38 UTC using RuboCop version 1.73.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -28,6 +28,12 @@ RSpec/RepeatedDescription:
28
28
  Exclude:
29
29
  - 'spec/csvbuilder/dynamic/columns/exporter/concerns/export/dynamic_columns_spec.rb'
30
30
 
31
+ # Offense count: 1
32
+ # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
33
+ RSpec/VerifiedDoubles:
34
+ Exclude:
35
+ - 'spec/csvbuilder/dynamic/columns/exporter/internal/export/dynamic_column_attribute_spec.rb'
36
+
31
37
  # Offense count: 2
32
38
  # Configuration parameters: AllowedConstants.
33
39
  Style/Documentation:
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.4.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.2] - 2024-02-27
4
+
5
+ - Update Ruby 3.4 and Relax Rails Constraint
6
+
7
+ ## [0.1.1] - 2022-12-30
8
+
9
+ Do not apply double formatting to the cells. The method `unformatted_value` should get the raw values from `source_cells`, not the value already formatted by row_model.format_cell.
10
+
3
11
  ## [0.1.0] - 2022-12-21
4
12
 
5
13
  - Initial release
data/Gemfile CHANGED
@@ -14,3 +14,5 @@ gem "rubocop"
14
14
  gem "rubocop-performance"
15
15
  gem "rubocop-rake"
16
16
  gem "rubocop-rspec"
17
+
18
+ # gem "csvbuilder-dynamic-columns-core", path: "../csvbuilder-dynamic-columns-core"
data/Gemfile.lock ADDED
@@ -0,0 +1,120 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ csvbuilder-dynamic-columns-exporter (0.1.2)
5
+ activesupport (>= 5.2, < 8)
6
+ csvbuilder-core (~> 0.1)
7
+ csvbuilder-dynamic-columns-core (~> 0.1)
8
+ csvbuilder-exporter (~> 0.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (7.2.2.1)
14
+ activesupport (= 7.2.2.1)
15
+ activesupport (7.2.2.1)
16
+ base64
17
+ benchmark (>= 0.3)
18
+ bigdecimal
19
+ concurrent-ruby (~> 1.0, >= 1.3.1)
20
+ connection_pool (>= 2.2.5)
21
+ drb
22
+ i18n (>= 1.6, < 2)
23
+ logger (>= 1.4.2)
24
+ minitest (>= 5.1)
25
+ securerandom (>= 0.3)
26
+ tzinfo (~> 2.0, >= 2.0.5)
27
+ ast (2.4.2)
28
+ base64 (0.2.0)
29
+ benchmark (0.4.0)
30
+ bigdecimal (3.1.9)
31
+ concurrent-ruby (1.3.5)
32
+ connection_pool (2.5.0)
33
+ csv (3.3.2)
34
+ csvbuilder-core (0.1.4)
35
+ activesupport (>= 5.2)
36
+ csv
37
+ csvbuilder-dynamic-columns-core (0.1.1)
38
+ activesupport (>= 5.2, < 8)
39
+ csvbuilder-core
40
+ csvbuilder-exporter (0.1.1)
41
+ activemodel (>= 5.2)
42
+ activesupport (>= 5.2)
43
+ csv
44
+ csvbuilder-core
45
+ diff-lcs (1.6.0)
46
+ drb (2.2.1)
47
+ i18n (1.14.7)
48
+ concurrent-ruby (~> 1.0)
49
+ json (2.10.1)
50
+ language_server-protocol (3.17.0.4)
51
+ lint_roller (1.1.0)
52
+ logger (1.6.6)
53
+ minitest (5.25.4)
54
+ parallel (1.26.3)
55
+ parser (3.3.7.1)
56
+ ast (~> 2.4.1)
57
+ racc
58
+ racc (1.8.1)
59
+ rainbow (3.1.1)
60
+ rake (13.2.1)
61
+ regexp_parser (2.10.0)
62
+ rspec (3.13.0)
63
+ rspec-core (~> 3.13.0)
64
+ rspec-expectations (~> 3.13.0)
65
+ rspec-mocks (~> 3.13.0)
66
+ rspec-core (3.13.3)
67
+ rspec-support (~> 3.13.0)
68
+ rspec-expectations (3.13.3)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.13.0)
71
+ rspec-mocks (3.13.2)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.13.0)
74
+ rspec-support (3.13.2)
75
+ rubocop (1.73.0)
76
+ json (~> 2.3)
77
+ language_server-protocol (~> 3.17.0.2)
78
+ lint_roller (~> 1.1.0)
79
+ parallel (~> 1.10)
80
+ parser (>= 3.3.0.2)
81
+ rainbow (>= 2.2.2, < 4.0)
82
+ regexp_parser (>= 2.9.3, < 3.0)
83
+ rubocop-ast (>= 1.38.0, < 2.0)
84
+ ruby-progressbar (~> 1.7)
85
+ unicode-display_width (>= 2.4.0, < 4.0)
86
+ rubocop-ast (1.38.1)
87
+ parser (>= 3.3.1.0)
88
+ rubocop-performance (1.24.0)
89
+ lint_roller (~> 1.1)
90
+ rubocop (>= 1.72.1, < 2.0)
91
+ rubocop-ast (>= 1.38.0, < 2.0)
92
+ rubocop-rake (0.7.1)
93
+ lint_roller (~> 1.1)
94
+ rubocop (>= 1.72.1)
95
+ rubocop-rspec (3.5.0)
96
+ lint_roller (~> 1.1)
97
+ rubocop (~> 1.72, >= 1.72.1)
98
+ ruby-progressbar (1.13.0)
99
+ securerandom (0.4.1)
100
+ tzinfo (2.0.6)
101
+ concurrent-ruby (~> 1.0)
102
+ unicode-display_width (3.1.4)
103
+ unicode-emoji (~> 4.0, >= 4.0.4)
104
+ unicode-emoji (4.0.4)
105
+
106
+ PLATFORMS
107
+ arm64-darwin-24
108
+ ruby
109
+
110
+ DEPENDENCIES
111
+ csvbuilder-dynamic-columns-exporter!
112
+ rake
113
+ rspec
114
+ rubocop
115
+ rubocop-performance
116
+ rubocop-rake
117
+ rubocop-rspec
118
+
119
+ BUNDLED WITH
120
+ 2.6.2
data/README.md CHANGED
@@ -1,22 +1,150 @@
1
- # Csvbuilder::Dynamic::Columns
1
+ # Csvbuilder::Dynamic::Columns::Exporter
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/csvbuilder/dynamic/columns`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [Csvbuilder::Dynamic::Columns::Exporter](https://github.com/joel/csvbuilder-dynamic-columns-exporter) is part of the [csvbuilder-collection](https://github.com/joel/csvbuilder)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ The Dynamic Columns Exporter contains the implementation for exporting a collection of objects within a variable group as a CSV file.
6
+
7
+ For instance, any object belonging to categories.
6
8
 
7
9
  ## Installation
8
10
 
9
11
  Install the gem and add to the application's Gemfile by executing:
10
12
 
11
- $ bundle add csvbuilder-dynamic-columns
13
+ $ bundle add csvbuilder-dynamic-columns-exporter
12
14
 
13
15
  If bundler is not being used to manage dependencies, install the gem by executing:
14
16
 
15
- $ gem install csvbuilder-dynamic-columns
17
+ $ gem install csvbuilder-dynamic-columns-exporter
16
18
 
17
19
  ## Usage
18
20
 
19
- TODO: Write usage instructions here
21
+ Let's consider a Developer with languages skill.
22
+
23
+ ```ruby
24
+ class UserCsvRowModel
25
+ include Csvbuilder::Model
26
+ include Csvbuilder::Export
27
+
28
+ column :name, header: "Developer"
29
+
30
+ dynamic_column :skills
31
+
32
+ def skill(skill_name)
33
+ source_model.skills.where(name: skill_name).exists? ? "1" : "0"
34
+ end
35
+ end
36
+ ```
37
+
38
+ For each Row, a method called by the singular version name of the declared Dynamic Columns will be called to determine the cell's value. In our example: `skill` must be implemented in the Exporter Model.
39
+
40
+ The `source_model` is provided and accessible within this method. In our example, it is the `User`. The File Exporter appends this object to the Row.
41
+
42
+ The dynamic part of the headers must be provided through the context under the same key name as the declared Dynamic Columns, here `skills`.
43
+
44
+ ```ruby
45
+ context = { skills: ["Ruby", "Python", "Javascript"] }
46
+
47
+ exporter = Csvbuilder::Export::File.new(UserCsvExportModel, context)
48
+
49
+ exporter.headers
50
+ # => ["Developer", "Ruby", "Python", "Javascript"]
51
+
52
+ sub_context = {} # it merged to the context
53
+
54
+ exporter.generate do |csv|
55
+ User.all.each do |user|
56
+ csv.append_model(user, sub_context) # user here is the source_model.
57
+ end
58
+ end
59
+
60
+ exporter.to_s
61
+ # => "Developer,Ruby,Python,Javascript\Bob,1,0,0\n"
62
+ ```
63
+
64
+ ## Format Dynamic Columns
65
+
66
+ Instead of taking care of the formatting directly in the dynamic cell method, here `skill`, it can be delegated to `format_dynamic_column_cells.`
67
+
68
+ Consider the following rewrite:
69
+
70
+ ```ruby
71
+ class UserCsvRowModel
72
+ include Csvbuilder::Model
73
+
74
+ column :name, header: "Developer"
75
+
76
+ dynamic_column :skills
77
+ end
78
+ ```
79
+
80
+ ```ruby
81
+ class UserCsvExportModel < UserCsvRowModel
82
+ include Csvbuilder::Export
83
+
84
+ def skill(skill_name)
85
+ source_model.skills.where(name: skill_name).exists?
86
+ end
87
+
88
+ class << self
89
+ def format_dynamic_column_cells(cells, _column_name, _context)
90
+ cells.map do |cell|
91
+ case cell
92
+ when true
93
+ "1"
94
+ when false
95
+ "0"
96
+ else
97
+ "N/A"
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ end
104
+ ```
105
+
106
+ ### Propagate default formatting
107
+
108
+ If a default formatting is defined, it will not automatically be propagated to the dynamic cells, which could cause edge cases.
109
+
110
+ ```ruby
111
+ class UserCsvRowModel
112
+ include Csvbuilder::Model
113
+
114
+ column :name
115
+
116
+ dynamic_column :skills
117
+
118
+ class << self
119
+
120
+ def format_cell(cell, _column_name, _context)
121
+ "- #{cell} -"
122
+ end
123
+
124
+ end
125
+ end
126
+ ```
127
+
128
+ To propagate it, recall the default formatting in dynamic columns formatting as follow:
129
+
130
+ ```ruby
131
+ class UserCsvExportModel < UserCsvRowModel
132
+ include Csvbuilder::Export
133
+
134
+ def skill(skill_name)
135
+ source_model.skills.where(name: skill_name).exists? ? "1" : "0"
136
+ end
137
+
138
+ class << self
139
+ def format_dynamic_column_cells(cells, _column_name, _context)
140
+ cells.map do |cell|
141
+ format_cell(cell, _column_name, _context)
142
+ end
143
+ end
144
+ end
145
+
146
+ end
147
+ ```
20
148
 
21
149
  ## Development
22
150
 
@@ -26,7 +154,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
26
154
 
27
155
  ## Contributing
28
156
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/csvbuilder-dynamic-columns. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/csvbuilder-dynamic-columns/blob/main/CODE_OF_CONDUCT.md).
157
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joel/csvbuilder-dynamic-columns. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/csvbuilder-dynamic-columns/blob/main/CODE_OF_CONDUCT.md).
30
158
 
31
159
  ## License
32
160
 
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  # Runtime dependencies
6
- gem "activesupport", "~> 5.2"
6
+ gem "activemodel", "~> 7.0"
7
7
 
8
8
  # Libraries dependencies
9
9
  gem "csvbuilder-core"
@@ -6,7 +6,7 @@ module Csvbuilder
6
6
  module Export
7
7
  class DynamicColumnAttribute < Csvbuilder::DynamicColumnAttributeBase
8
8
  def unformatted_value
9
- formatted_cells
9
+ source_cells
10
10
  end
11
11
 
12
12
  def source_cells
@@ -4,7 +4,7 @@ module Csvbuilder
4
4
  module Dynamic
5
5
  module Columns
6
6
  module Exporter
7
- VERSION = "0.1.0"
7
+ VERSION = "0.1.2"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csvbuilder-dynamic-columns-exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Azemar
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-12-23 00:00:00.000000000 Z
10
+ date: 2025-02-27 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -34,44 +33,44 @@ dependencies:
34
33
  name: csvbuilder-core
35
34
  requirement: !ruby/object:Gem::Requirement
36
35
  requirements:
37
- - - ">="
36
+ - - "~>"
38
37
  - !ruby/object:Gem::Version
39
- version: '0'
38
+ version: '0.1'
40
39
  type: :runtime
41
40
  prerelease: false
42
41
  version_requirements: !ruby/object:Gem::Requirement
43
42
  requirements:
44
- - - ">="
43
+ - - "~>"
45
44
  - !ruby/object:Gem::Version
46
- version: '0'
45
+ version: '0.1'
47
46
  - !ruby/object:Gem::Dependency
48
47
  name: csvbuilder-dynamic-columns-core
49
48
  requirement: !ruby/object:Gem::Requirement
50
49
  requirements:
51
- - - ">="
50
+ - - "~>"
52
51
  - !ruby/object:Gem::Version
53
- version: '0'
52
+ version: '0.1'
54
53
  type: :runtime
55
54
  prerelease: false
56
55
  version_requirements: !ruby/object:Gem::Requirement
57
56
  requirements:
58
- - - ">="
57
+ - - "~>"
59
58
  - !ruby/object:Gem::Version
60
- version: '0'
59
+ version: '0.1'
61
60
  - !ruby/object:Gem::Dependency
62
61
  name: csvbuilder-exporter
63
62
  requirement: !ruby/object:Gem::Requirement
64
63
  requirements:
65
- - - ">="
64
+ - - "~>"
66
65
  - !ruby/object:Gem::Version
67
- version: '0'
66
+ version: '0.1'
68
67
  type: :runtime
69
68
  prerelease: false
70
69
  version_requirements: !ruby/object:Gem::Requirement
71
70
  requirements:
72
- - - ">="
71
+ - - "~>"
73
72
  - !ruby/object:Gem::Version
74
- version: '0'
73
+ version: '0.1'
75
74
  description: Help handle CSVs in a more efficient way
76
75
  email:
77
76
  - joel.azemar@gmail.com
@@ -83,15 +82,16 @@ files:
83
82
  - ".rspec"
84
83
  - ".rubocop.yml"
85
84
  - ".rubocop_todo.yml"
85
+ - ".tool-versions"
86
86
  - CHANGELOG.md
87
87
  - CODE_OF_CONDUCT.md
88
88
  - Gemfile
89
+ - Gemfile.lock
89
90
  - LICENSE.txt
90
91
  - README.md
91
92
  - Rakefile
92
- - gemfiles/Gemfile.5.2._gemfile
93
- - gemfiles/Gemfile.6.1._gemfile
94
93
  - gemfiles/Gemfile.7.0._gemfile
94
+ - gemfiles/Gemfile.8.0._gemfile
95
95
  - lib/.DS_Store
96
96
  - lib/csvbuilder/.DS_Store
97
97
  - lib/csvbuilder/dynamic/.DS_Store
@@ -113,7 +113,6 @@ metadata:
113
113
  source_code_uri: https://github.com/joel/csvbuilder-dynamic-columns-exporter
114
114
  changelog_uri: https://github.com/joel/csvbuilder-dynamic-columns-exporter/blob/main/CHANGELOG.md
115
115
  rubygems_mfa_required: 'true'
116
- post_install_message:
117
116
  rdoc_options: []
118
117
  require_paths:
119
118
  - lib
@@ -121,15 +120,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
120
  requirements:
122
121
  - - ">="
123
122
  - !ruby/object:Gem::Version
124
- version: 2.6.0
123
+ version: '3.4'
125
124
  required_rubygems_version: !ruby/object:Gem::Requirement
126
125
  requirements:
127
126
  - - ">="
128
127
  - !ruby/object:Gem::Version
129
128
  version: '0'
130
129
  requirements: []
131
- rubygems_version: 3.3.22
132
- signing_key:
130
+ rubygems_version: 3.6.2
133
131
  specification_version: 4
134
132
  summary: Csvbuilder Dynamic Columns contain the components to handle CSV dynamic columns
135
133
  test_files: []
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Runtime dependencies
6
- gem "activesupport", "~> 6.1"
7
-
8
- # Libraries dependencies
9
- gem "csvbuilder-core"
10
- gem "csvbuilder-dynamic-columns-core"
11
- gem "csvbuilder-exporter"
12
-
13
- # Development dependencies
14
- gem "rake"
15
- gem "rspec"
16
- gem "rubocop"
17
- gem "rubocop-performance"
18
- gem "rubocop-rake"
19
- gem "rubocop-rspec"