csvbuilder-collection 0.1.2 → 0.2.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/.rubocop.yml +3 -3
- data/.rubocop_todo.yml +65 -16
- data/.tool-versions +1 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile +9 -2
- data/Gemfile.lock +171 -0
- data/README.md +140 -4
- data/gemfiles/Gemfile.7.0._gemfile +2 -0
- data/gemfiles/{Gemfile.5.2._gemfile → Gemfile.8.0._gemfile} +6 -3
- data/lib/csvbuilder/version.rb +1 -1
- metadata +20 -43
- data/gemfiles/Gemfile.6.1._gemfile +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb1863fff226d4affdeca5ba147a79cede94eeaec6df640d868d834d6e71d98d
|
4
|
+
data.tar.gz: e49db83ce9a8c36846de4b8a6a72fcf0024d7812ad07cfcdee673e58d5cf8f28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c87bf0f60530f035775200df6d7414b987a542a992f66c081e7c03b1677767bde6243bf95f96863097e3694980b1417224590efa1c34fb21a25099b8ed1467e
|
7
|
+
data.tar.gz: 2f0a532c6b3db4eb90c89816a48e6ec463e1b62d93252ed163b122a6dd181ea9fc3c194bcde29e1ddaa19d8f2bb9d4597a06e283432e0f4205665a665e025911
|
data/.rubocop.yml
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
2
2
|
|
3
|
-
|
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:
|
10
|
+
TargetRubyVersion: 3.4
|
11
11
|
|
12
12
|
Style/StringLiterals:
|
13
13
|
Enabled: true
|
@@ -18,4 +18,4 @@ Style/StringLiteralsInInterpolation:
|
|
18
18
|
EnforcedStyle: double_quotes
|
19
19
|
|
20
20
|
Layout/LineLength:
|
21
|
-
Max:
|
21
|
+
Max: 135
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2025-03-02 07:09:13 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
|
@@ -8,31 +8,80 @@
|
|
8
8
|
|
9
9
|
# Offense count: 1
|
10
10
|
# This cop supports safe autocorrection (--autocorrect).
|
11
|
-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns,
|
11
|
+
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
12
12
|
# URISchemes: http, https
|
13
13
|
Layout/LineLength:
|
14
|
-
Max: 130
|
15
14
|
Exclude:
|
16
|
-
- 'spec/
|
15
|
+
- 'spec/integrations/import/dynamic-columns/import_by_static_columns_spec.rb'
|
17
16
|
|
18
|
-
# Offense count:
|
19
|
-
# Configuration parameters:
|
20
|
-
|
21
|
-
Max:
|
17
|
+
# Offense count: 1
|
18
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
19
|
+
Metrics/AbcSize:
|
20
|
+
Max: 20
|
22
21
|
|
23
22
|
# Offense count: 2
|
24
|
-
|
25
|
-
|
23
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
24
|
+
Metrics/MethodLength:
|
25
|
+
Max: 17
|
26
26
|
|
27
27
|
# Offense count: 3
|
28
|
-
# Configuration parameters:
|
29
|
-
|
30
|
-
|
28
|
+
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
|
29
|
+
# SupportedStyles: snake_case, normalcase, non_integer
|
30
|
+
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
|
31
|
+
Naming/VariableNumber:
|
32
|
+
Exclude:
|
33
|
+
- 'spec/integrations/import/dynamic-columns/import_by_static_columns_spec.rb'
|
34
|
+
|
35
|
+
# Offense count: 1
|
36
|
+
RSpec/AnyInstance:
|
37
|
+
Exclude:
|
38
|
+
- 'spec/integrations/import/dynamic-columns/import_by_static_columns_spec.rb'
|
39
|
+
|
40
|
+
# Offense count: 9
|
41
|
+
# Configuration parameters: IgnoredMetadata.
|
42
|
+
RSpec/DescribeClass:
|
43
|
+
Exclude:
|
44
|
+
- '**/spec/features/**/*'
|
45
|
+
- '**/spec/requests/**/*'
|
46
|
+
- '**/spec/routing/**/*'
|
47
|
+
- '**/spec/system/**/*'
|
48
|
+
- '**/spec/views/**/*'
|
49
|
+
- 'spec/integrations/export/dynamic-columns/aliasing_as_export_spec.rb'
|
50
|
+
- 'spec/integrations/export/dynamic-columns/export_spec.rb'
|
51
|
+
- 'spec/integrations/export/dynamic-columns/formatted_dynamic_column_cells_export_spec.rb'
|
52
|
+
- 'spec/integrations/export/dynamic-columns/formatted_dynamic_column_headers_export_spec.rb'
|
53
|
+
- 'spec/integrations/import/dynamic-columns/formatted_dynamic_column_cells_spec.rb'
|
54
|
+
- 'spec/integrations/import/dynamic-columns/formatted_dynamic_column_headers_spec.rb'
|
55
|
+
- 'spec/integrations/import/dynamic-columns/import_by_static_columns_spec.rb'
|
56
|
+
- 'spec/integrations/import/dynamic-columns/import_spec.rb'
|
57
|
+
- 'spec/integrations/import/dynamic-columns/validate_dynamic_header_values_spec.rb'
|
31
58
|
|
32
|
-
# Offense count:
|
59
|
+
# Offense count: 17
|
60
|
+
# Configuration parameters: CountAsOne.
|
61
|
+
RSpec/ExampleLength:
|
62
|
+
Max: 31
|
63
|
+
|
64
|
+
# Offense count: 14
|
65
|
+
RSpec/MultipleExpectations:
|
66
|
+
Max: 14
|
67
|
+
|
68
|
+
# Offense count: 27
|
33
69
|
# Configuration parameters: AllowedGroups.
|
34
70
|
RSpec/NestedGroups:
|
35
|
-
Max:
|
71
|
+
Max: 6
|
72
|
+
|
73
|
+
# Offense count: 1
|
74
|
+
RSpec/RemoveConst:
|
75
|
+
Exclude:
|
76
|
+
- 'spec/integrations/import/dynamic-columns/import_by_static_columns_spec.rb'
|
36
77
|
|
78
|
+
# Offense count: 2
|
79
|
+
RSpec/RepeatedExample:
|
80
|
+
Exclude:
|
81
|
+
- 'spec/integrations/export/dynamic-columns/formatted_dynamic_column_cells_export_spec.rb'
|
82
|
+
|
83
|
+
# Offense count: 2
|
37
84
|
Style/OpenStructUse:
|
38
|
-
|
85
|
+
Exclude:
|
86
|
+
- 'spec/integrations/import/dynamic-columns/formatted_dynamic_column_cells_spec.rb'
|
87
|
+
- 'spec/integrations/import/dynamic-columns/formatted_dynamic_column_headers_spec.rb'
|
data/.tool-versions
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby
|
1
|
+
ruby 3.4.2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.0] - 2025-03-02 Sun 2 Mar 2025
|
4
|
+
|
5
|
+
- Using [csvbuilder-importer](https://github.com/joel/csvbuilder-importer/tree/v0.2.0)
|
6
|
+
- Check if the headers from the CSV match the Csvbuilder::Model headers definitions.
|
7
|
+
|
3
8
|
## [0.1.0] - 2022-12-16
|
4
9
|
|
5
10
|
- Initial release
|
data/Gemfile
CHANGED
@@ -15,8 +15,15 @@ gem "rubocop-performance"
|
|
15
15
|
gem "rubocop-rake"
|
16
16
|
gem "rubocop-rspec"
|
17
17
|
|
18
|
+
gem "activerecord"
|
19
|
+
gem "database_cleaner-active_record"
|
20
|
+
|
21
|
+
gem "ostruct"
|
22
|
+
gem "sqlite3"
|
23
|
+
|
18
24
|
# gem "csvbuilder-core", path: "../csvbuilder-core"
|
19
|
-
# gem "csvbuilder-importer", path: "../csvbuilder-importer"
|
20
|
-
# gem "csvbuilder-exporter", path: "../csvbuilder-exporter"
|
21
25
|
# gem "csvbuilder-dynamic-columns-core", path: "../csvbuilder-dynamic-columns-core"
|
26
|
+
# gem "csvbuilder-dynamic-columns-exporter", path: "../csvbuilder-dynamic-columns-exporter"
|
22
27
|
# gem "csvbuilder-dynamic-columns-importer", path: "../csvbuilder-dynamic-columns-importer"
|
28
|
+
# gem "csvbuilder-exporter", path: "../csvbuilder-exporter"
|
29
|
+
# gem "csvbuilder-importer", path: "../csvbuilder-importer"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
csvbuilder-collection (0.2.0)
|
5
|
+
csv
|
6
|
+
csvbuilder-core (~> 0.1)
|
7
|
+
csvbuilder-dynamic-columns-core (~> 0.1)
|
8
|
+
csvbuilder-dynamic-columns-exporter (~> 0.1)
|
9
|
+
csvbuilder-dynamic-columns-importer (~> 0.1)
|
10
|
+
csvbuilder-exporter (~> 0.1)
|
11
|
+
csvbuilder-importer (~> 0.1)
|
12
|
+
|
13
|
+
GEM
|
14
|
+
remote: https://rubygems.org/
|
15
|
+
specs:
|
16
|
+
activemodel (7.2.2.1)
|
17
|
+
activesupport (= 7.2.2.1)
|
18
|
+
activerecord (7.2.2.1)
|
19
|
+
activemodel (= 7.2.2.1)
|
20
|
+
activesupport (= 7.2.2.1)
|
21
|
+
timeout (>= 0.4.0)
|
22
|
+
activesupport (7.2.2.1)
|
23
|
+
base64
|
24
|
+
benchmark (>= 0.3)
|
25
|
+
bigdecimal
|
26
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
27
|
+
connection_pool (>= 2.2.5)
|
28
|
+
drb
|
29
|
+
i18n (>= 1.6, < 2)
|
30
|
+
logger (>= 1.4.2)
|
31
|
+
minitest (>= 5.1)
|
32
|
+
securerandom (>= 0.3)
|
33
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
34
|
+
ast (2.4.2)
|
35
|
+
base64 (0.2.0)
|
36
|
+
benchmark (0.4.0)
|
37
|
+
bigdecimal (3.1.9)
|
38
|
+
concurrent-ruby (1.3.5)
|
39
|
+
connection_pool (2.5.0)
|
40
|
+
csv (3.3.2)
|
41
|
+
csvbuilder-core (0.1.4)
|
42
|
+
activesupport (>= 5.2)
|
43
|
+
csv
|
44
|
+
csvbuilder-dynamic-columns-core (0.1.2)
|
45
|
+
activesupport (>= 5.2)
|
46
|
+
csv
|
47
|
+
csvbuilder-core
|
48
|
+
csvbuilder-dynamic-columns-exporter (0.1.3)
|
49
|
+
activesupport (>= 5.2)
|
50
|
+
csvbuilder-core (~> 0.1)
|
51
|
+
csvbuilder-dynamic-columns-core (~> 0.1)
|
52
|
+
csvbuilder-exporter (~> 0.1)
|
53
|
+
csvbuilder-dynamic-columns-importer (0.1.2)
|
54
|
+
activesupport (>= 5.2)
|
55
|
+
csvbuilder-core (~> 0.1)
|
56
|
+
csvbuilder-dynamic-columns-core (~> 0.1)
|
57
|
+
csvbuilder-importer (~> 0.1)
|
58
|
+
csvbuilder-exporter (0.1.1)
|
59
|
+
activemodel (>= 5.2)
|
60
|
+
activesupport (>= 5.2)
|
61
|
+
csv
|
62
|
+
csvbuilder-core
|
63
|
+
csvbuilder-importer (0.2.0)
|
64
|
+
activemodel (>= 5.2)
|
65
|
+
activesupport (>= 5.2)
|
66
|
+
csv
|
67
|
+
csvbuilder-core
|
68
|
+
database_cleaner-active_record (2.2.0)
|
69
|
+
activerecord (>= 5.a)
|
70
|
+
database_cleaner-core (~> 2.0.0)
|
71
|
+
database_cleaner-core (2.0.1)
|
72
|
+
diff-lcs (1.6.0)
|
73
|
+
drb (2.2.1)
|
74
|
+
i18n (1.14.7)
|
75
|
+
concurrent-ruby (~> 1.0)
|
76
|
+
json (2.10.1)
|
77
|
+
language_server-protocol (3.17.0.4)
|
78
|
+
lint_roller (1.1.0)
|
79
|
+
logger (1.6.6)
|
80
|
+
minitest (5.25.4)
|
81
|
+
ostruct (0.6.1)
|
82
|
+
parallel (1.26.3)
|
83
|
+
parser (3.3.7.1)
|
84
|
+
ast (~> 2.4.1)
|
85
|
+
racc
|
86
|
+
racc (1.8.1)
|
87
|
+
rainbow (3.1.1)
|
88
|
+
rake (13.2.1)
|
89
|
+
regexp_parser (2.10.0)
|
90
|
+
rspec (3.13.0)
|
91
|
+
rspec-core (~> 3.13.0)
|
92
|
+
rspec-expectations (~> 3.13.0)
|
93
|
+
rspec-mocks (~> 3.13.0)
|
94
|
+
rspec-core (3.13.3)
|
95
|
+
rspec-support (~> 3.13.0)
|
96
|
+
rspec-expectations (3.13.3)
|
97
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
98
|
+
rspec-support (~> 3.13.0)
|
99
|
+
rspec-mocks (3.13.2)
|
100
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
101
|
+
rspec-support (~> 3.13.0)
|
102
|
+
rspec-support (3.13.2)
|
103
|
+
rubocop (1.72.2)
|
104
|
+
json (~> 2.3)
|
105
|
+
language_server-protocol (~> 3.17.0.2)
|
106
|
+
lint_roller (~> 1.1.0)
|
107
|
+
parallel (~> 1.10)
|
108
|
+
parser (>= 3.3.0.2)
|
109
|
+
rainbow (>= 2.2.2, < 4.0)
|
110
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
111
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
112
|
+
ruby-progressbar (~> 1.7)
|
113
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
114
|
+
rubocop-ast (1.38.1)
|
115
|
+
parser (>= 3.3.1.0)
|
116
|
+
rubocop-performance (1.24.0)
|
117
|
+
lint_roller (~> 1.1)
|
118
|
+
rubocop (>= 1.72.1, < 2.0)
|
119
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
120
|
+
rubocop-rake (0.7.1)
|
121
|
+
lint_roller (~> 1.1)
|
122
|
+
rubocop (>= 1.72.1)
|
123
|
+
rubocop-rspec (3.5.0)
|
124
|
+
lint_roller (~> 1.1)
|
125
|
+
rubocop (~> 1.72, >= 1.72.1)
|
126
|
+
ruby-progressbar (1.13.0)
|
127
|
+
securerandom (0.4.1)
|
128
|
+
sqlite3 (2.6.0-aarch64-linux-gnu)
|
129
|
+
sqlite3 (2.6.0-aarch64-linux-musl)
|
130
|
+
sqlite3 (2.6.0-arm-linux-gnu)
|
131
|
+
sqlite3 (2.6.0-arm-linux-musl)
|
132
|
+
sqlite3 (2.6.0-arm64-darwin)
|
133
|
+
sqlite3 (2.6.0-x86-linux-gnu)
|
134
|
+
sqlite3 (2.6.0-x86-linux-musl)
|
135
|
+
sqlite3 (2.6.0-x86_64-darwin)
|
136
|
+
sqlite3 (2.6.0-x86_64-linux-gnu)
|
137
|
+
sqlite3 (2.6.0-x86_64-linux-musl)
|
138
|
+
timeout (0.4.3)
|
139
|
+
tzinfo (2.0.6)
|
140
|
+
concurrent-ruby (~> 1.0)
|
141
|
+
unicode-display_width (3.1.4)
|
142
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
143
|
+
unicode-emoji (4.0.4)
|
144
|
+
|
145
|
+
PLATFORMS
|
146
|
+
aarch64-linux-gnu
|
147
|
+
aarch64-linux-musl
|
148
|
+
arm-linux-gnu
|
149
|
+
arm-linux-musl
|
150
|
+
arm64-darwin
|
151
|
+
x86-linux-gnu
|
152
|
+
x86-linux-musl
|
153
|
+
x86_64-darwin
|
154
|
+
x86_64-linux-gnu
|
155
|
+
x86_64-linux-musl
|
156
|
+
|
157
|
+
DEPENDENCIES
|
158
|
+
activerecord
|
159
|
+
csvbuilder-collection!
|
160
|
+
database_cleaner-active_record
|
161
|
+
ostruct
|
162
|
+
rake
|
163
|
+
rspec
|
164
|
+
rubocop
|
165
|
+
rubocop-performance
|
166
|
+
rubocop-rake
|
167
|
+
rubocop-rspec
|
168
|
+
sqlite3
|
169
|
+
|
170
|
+
BUNDLED WITH
|
171
|
+
2.6.2
|
data/README.md
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
# Csvbuilder
|
2
2
|
|
3
|
-
|
3
|
+
[Csvbuilder](https://rubygems.org/gems/csvbuilder-collection) is a wrapper for a collection of libraries that lets you export and import CSV data easily.
|
4
4
|
|
5
|
-
|
5
|
+
It carries [integration specs](https://github.com/joel/csvbuilder/tree/main/spec/integrations) which are perfect for understanding all the feature of `csvbuilder` and having a concrete example of how each part work.
|
6
|
+
|
7
|
+
1. [csvbuilder-core](https://rubygems.org/gems/csvbuilder-core)
|
8
|
+
2. [csvbuilder-dynamic-columns-core](https://rubygems.org/gems/csvbuilder-dynamic-columns-core)
|
9
|
+
|
10
|
+
This library was written to be extendable in mind. The extremely modular set of libraries lets you extend your application's functionalities to best suit your need.
|
11
|
+
|
12
|
+
Feel free to install only what your application needs.
|
6
13
|
|
7
14
|
## Installation
|
8
15
|
|
@@ -16,7 +23,136 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
16
23
|
|
17
24
|
## Usage
|
18
25
|
|
19
|
-
|
26
|
+
# Model
|
27
|
+
|
28
|
+
The library comes we a nice simple DSL. The model should correspond to the headers and cells of a CSV row.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
class UserRowModel
|
32
|
+
include Csvbuilder::Model
|
33
|
+
|
34
|
+
column :first_name
|
35
|
+
column :last_name
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Generally, the defined columns will match your database columns. But it is definitely not necessary.
|
40
|
+
|
41
|
+
The model is meant to be the standard area for import and export. We'll see in the next section how those two differ.
|
42
|
+
|
43
|
+
[More on Model](https://github.com/joel/csvbuilder-core)
|
44
|
+
|
45
|
+
# Exporting
|
46
|
+
|
47
|
+
If you want to add a piece of information for export only, like in the following example, the Corporate Email, you can compute data in the Export Class.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
class UserExportModel < UserRowModel
|
51
|
+
include Csvbuilder::Export
|
52
|
+
|
53
|
+
column :email, header: "Corporate Email"
|
54
|
+
|
55
|
+
def email
|
56
|
+
"#{first_name}.#{last_name}@example.co.uk".downcase
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
## How to export
|
62
|
+
|
63
|
+
You need to provide both object collection and exporter class as follow:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
collection = [OpenStruct.new(first_name: "John", last_name: "Doe", full_name: "John Doe")]
|
67
|
+
|
68
|
+
exporter = Csvbuilder::Export::File.new(UserExportModel, context = {})
|
69
|
+
|
70
|
+
exporter.headers
|
71
|
+
# => "First Name", "Last Name", "Full Name", "Email"
|
72
|
+
|
73
|
+
exporter.generate do |csv|
|
74
|
+
collection.each do |user|
|
75
|
+
csv.append_model(user, another_context: true)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
# => "First Name,Last Name,Full Name,Email\nJohn,Doe,John Doe,john.doe@example.co.uk\n"
|
79
|
+
```
|
80
|
+
|
81
|
+
[More on Exporter](https://github.com/joel/csvbuilder-exporter)
|
82
|
+
|
83
|
+
# Importing
|
84
|
+
|
85
|
+
The importing part is the more critical part. It carries validations to handle complex use cases. You have all the power of the `ActiveModel::Validations`. The validations happen in the importer class, and it acts as policies. You can couple them with the model itself, though. It is still recommended to handle model errors at a higher level to not pair the `ImportModel` with the model too much.
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
class UserImportModel < UserRowModel
|
89
|
+
include Csvbuilder::Import
|
90
|
+
|
91
|
+
validates :first_name, presence: true, length: { minimum: 2 }
|
92
|
+
validates :last_name, presence: true, length: { minimum: 2 }
|
93
|
+
|
94
|
+
def full_name
|
95
|
+
"#{first_name} #{last_name}"
|
96
|
+
end
|
97
|
+
|
98
|
+
def user
|
99
|
+
User.new(first_name: first_name, last_name: last_name, full_name: full_name)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Skip if the row is not valid, the user is not valid or the user already exists
|
103
|
+
def skip?
|
104
|
+
super || !user.valid? || user.exists?
|
105
|
+
end
|
106
|
+
|
107
|
+
# Abort the import
|
108
|
+
def abort?
|
109
|
+
"#{first_name} #{last_name}" == "Bill Gates"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
## How to import
|
115
|
+
|
116
|
+
For importing, you must provide the CSV file and the Import Class. The `Import::File` will skip an invalid importer, a not valid user or an already existing user.
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
csv_source = [
|
120
|
+
["First name", "Last name"],
|
121
|
+
["John" , "Doe" ],
|
122
|
+
]
|
123
|
+
|
124
|
+
CSV.generate do |csv|
|
125
|
+
csv_source.each { |row| csv << row }
|
126
|
+
end
|
127
|
+
|
128
|
+
file = Tempfile.new(["input_file", ".csv"])
|
129
|
+
|
130
|
+
Csvbuilder::Import::File
|
131
|
+
.new(file.path, UserImportModel, options = {}).each do |row_model|
|
132
|
+
row_model.user.save
|
133
|
+
end
|
134
|
+
```
|
135
|
+
|
136
|
+
[More on Importer](https://github.com/joel/csvbuilder-importer)
|
137
|
+
|
138
|
+
# Dynamic columns
|
139
|
+
|
140
|
+
The headers are dynamic and take a collection, so it doesn’t need a strict definition like other columns. Dynamic columns are a relation between header value and cell value.
|
141
|
+
|
142
|
+
[More on dynamic columns](https://github.com/joel/csvbuilder-dynamic-columns-core)
|
143
|
+
|
144
|
+
## Credits
|
145
|
+
|
146
|
+
This project is inspired by the open-source library [CsvRowModel](https://github.com/finalcad/csv_row_model) written by [Steve Chung](https://github.com/s12chung). Unfortunately, this library is unmaintained and currently broken, and it depends on other unmaintained libraries. The purpose is to keep the core concepts and the architecture, removing all non-essential features and unmaintained dependencies and adding test coverage with Rails and Ruby matrices to track any broken version, past and future. Splitting the library into several gems lets projects use only the needed parts.
|
147
|
+
|
148
|
+
## Dependencies
|
149
|
+
|
150
|
+
1. [csvbuilder-core](https://rubygems.org/gems/csvbuilder-core)
|
151
|
+
2. [csvbuilder-exporter](https://rubygems.org/gems/csvbuilder-exporter)
|
152
|
+
3. [csvbuilder-importer](https://rubygems.org/gems/csvbuilder-importer)
|
153
|
+
4. [csvbuilder-dynamic-columns-core](https://rubygems.org/gems/csvbuilder-dynamic-columns-core)
|
154
|
+
5. [csvbuilder-dynamic-columns-exporter](https://rubygems.org/gems/csvbuilder-dynamic-columns-exporter)
|
155
|
+
6. [csvbuilder-dynamic-columns-importer](https://rubygems.org/gems/csvbuilder-dynamic-columns-importer)
|
20
156
|
|
21
157
|
## Development
|
22
158
|
|
@@ -26,7 +162,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
26
162
|
|
27
163
|
## Contributing
|
28
164
|
|
29
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
165
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/joel/csvbuilder. 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/blob/main/CODE_OF_CONDUCT.md).
|
30
166
|
|
31
167
|
## License
|
32
168
|
|
@@ -5,6 +5,7 @@ source "https://rubygems.org"
|
|
5
5
|
# Runtime dependencies
|
6
6
|
gem "activemodel", "~> 7.0"
|
7
7
|
gem "activerecord", "~> 7.0"
|
8
|
+
gem "csv"
|
8
9
|
|
9
10
|
# Libraries dependencies
|
10
11
|
gem "csvbuilder-core"
|
@@ -17,6 +18,7 @@ gem "csvbuilder-dynamic-columns-importer"
|
|
17
18
|
# Test dependencies
|
18
19
|
gem "activesupport", "~> 7.0"
|
19
20
|
gem "sqlite3"
|
21
|
+
gem "database_cleaner"
|
20
22
|
|
21
23
|
# Development dependencies
|
22
24
|
gem "rake"
|
@@ -3,8 +3,10 @@
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
5
|
# Runtime dependencies
|
6
|
-
gem "activemodel", "~>
|
7
|
-
gem "activerecord", "~>
|
6
|
+
gem "activemodel", "~> 8.0"
|
7
|
+
gem "activerecord", "~> 8.0"
|
8
|
+
gem "csv"
|
9
|
+
gem "mutex_m"
|
8
10
|
|
9
11
|
# Libraries dependencies
|
10
12
|
gem "csvbuilder-core"
|
@@ -15,8 +17,9 @@ gem "csvbuilder-importer"
|
|
15
17
|
gem "csvbuilder-dynamic-columns-importer"
|
16
18
|
|
17
19
|
# Test dependencies
|
18
|
-
gem "activesupport", "~>
|
20
|
+
gem "activesupport", "~> 8.0"
|
19
21
|
gem "sqlite3"
|
22
|
+
gem "database_cleaner-active_record"
|
20
23
|
|
21
24
|
# Development dependencies
|
22
25
|
gem "rake"
|
data/lib/csvbuilder/version.rb
CHANGED
metadata
CHANGED
@@ -1,31 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csvbuilder-collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Azemar
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
13
|
+
name: csv
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- - "
|
16
|
+
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
18
|
+
version: '0'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
|
-
- - "
|
23
|
+
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
25
|
+
version: '0'
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: csvbuilder-
|
27
|
+
name: csvbuilder-core
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - "~>"
|
@@ -39,7 +38,7 @@ dependencies:
|
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: '0.1'
|
41
40
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: csvbuilder-dynamic-columns-
|
41
|
+
name: csvbuilder-dynamic-columns-core
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - "~>"
|
@@ -53,7 +52,7 @@ dependencies:
|
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: '0.1'
|
55
54
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: csvbuilder-dynamic-columns-
|
55
|
+
name: csvbuilder-dynamic-columns-exporter
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
58
|
- - "~>"
|
@@ -67,7 +66,7 @@ dependencies:
|
|
67
66
|
- !ruby/object:Gem::Version
|
68
67
|
version: '0.1'
|
69
68
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: csvbuilder-
|
69
|
+
name: csvbuilder-dynamic-columns-importer
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
72
71
|
requirements:
|
73
72
|
- - "~>"
|
@@ -81,7 +80,7 @@ dependencies:
|
|
81
80
|
- !ruby/object:Gem::Version
|
82
81
|
version: '0.1'
|
83
82
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: csvbuilder-
|
83
|
+
name: csvbuilder-exporter
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
86
85
|
requirements:
|
87
86
|
- - "~>"
|
@@ -95,39 +94,19 @@ dependencies:
|
|
95
94
|
- !ruby/object:Gem::Version
|
96
95
|
version: '0.1'
|
97
96
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '5.2'
|
104
|
-
- - "<"
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
version: '8'
|
107
|
-
type: :development
|
108
|
-
prerelease: false
|
109
|
-
version_requirements: !ruby/object:Gem::Requirement
|
110
|
-
requirements:
|
111
|
-
- - ">="
|
112
|
-
- !ruby/object:Gem::Version
|
113
|
-
version: '5.2'
|
114
|
-
- - "<"
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '8'
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
|
-
name: sqlite3
|
97
|
+
name: csvbuilder-importer
|
119
98
|
requirement: !ruby/object:Gem::Requirement
|
120
99
|
requirements:
|
121
100
|
- - "~>"
|
122
101
|
- !ruby/object:Gem::Version
|
123
|
-
version: '1
|
124
|
-
type: :
|
102
|
+
version: '0.1'
|
103
|
+
type: :runtime
|
125
104
|
prerelease: false
|
126
105
|
version_requirements: !ruby/object:Gem::Requirement
|
127
106
|
requirements:
|
128
107
|
- - "~>"
|
129
108
|
- !ruby/object:Gem::Version
|
130
|
-
version: '1
|
109
|
+
version: '0.1'
|
131
110
|
description: Help handle CSVs in a more efficient way
|
132
111
|
email:
|
133
112
|
- joel.azemar@gmail.com
|
@@ -142,12 +121,12 @@ files:
|
|
142
121
|
- CHANGELOG.md
|
143
122
|
- CODE_OF_CONDUCT.md
|
144
123
|
- Gemfile
|
124
|
+
- Gemfile.lock
|
145
125
|
- LICENSE.txt
|
146
126
|
- README.md
|
147
127
|
- Rakefile
|
148
|
-
- gemfiles/Gemfile.5.2._gemfile
|
149
|
-
- gemfiles/Gemfile.6.1._gemfile
|
150
128
|
- gemfiles/Gemfile.7.0._gemfile
|
129
|
+
- gemfiles/Gemfile.8.0._gemfile
|
151
130
|
- lib/csvbuilder.rb
|
152
131
|
- lib/csvbuilder/version.rb
|
153
132
|
- sig/csvbuilder.rbs
|
@@ -159,7 +138,6 @@ metadata:
|
|
159
138
|
source_code_uri: https://github.com/joel/csvbuilder
|
160
139
|
changelog_uri: https://github.com/joel/csvbuilder/blob/main/CHANGELOG.md
|
161
140
|
rubygems_mfa_required: 'true'
|
162
|
-
post_install_message:
|
163
141
|
rdoc_options: []
|
164
142
|
require_paths:
|
165
143
|
- lib
|
@@ -167,15 +145,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
145
|
requirements:
|
168
146
|
- - ">="
|
169
147
|
- !ruby/object:Gem::Version
|
170
|
-
version:
|
148
|
+
version: '3.4'
|
171
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
150
|
requirements:
|
173
151
|
- - ">="
|
174
152
|
- !ruby/object:Gem::Version
|
175
153
|
version: '0'
|
176
154
|
requirements: []
|
177
|
-
rubygems_version: 3.
|
178
|
-
signing_key:
|
155
|
+
rubygems_version: 3.6.2
|
179
156
|
specification_version: 4
|
180
157
|
summary: Csvbuilder provide a nice DSL to import and export the CSVs
|
181
158
|
test_files: []
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
# Runtime dependencies
|
6
|
-
gem "activemodel", "~> 6.1"
|
7
|
-
gem "activerecord", "~> 6.1"
|
8
|
-
|
9
|
-
# Libraries dependencies
|
10
|
-
gem "csvbuilder-core"
|
11
|
-
gem "csvbuilder-dynamic-columns-core"
|
12
|
-
gem "csvbuilder-exporter"
|
13
|
-
gem "csvbuilder-dynamic-columns-exporter"
|
14
|
-
gem "csvbuilder-importer"
|
15
|
-
gem "csvbuilder-dynamic-columns-importer"
|
16
|
-
|
17
|
-
# Test dependencies
|
18
|
-
gem "activesupport", "~> 6.1"
|
19
|
-
gem "sqlite3"
|
20
|
-
|
21
|
-
# Development dependencies
|
22
|
-
gem "rake"
|
23
|
-
gem "rspec"
|
24
|
-
gem "rubocop"
|
25
|
-
gem "rubocop-performance"
|
26
|
-
gem "rubocop-rake"
|
27
|
-
gem "rubocop-rspec"
|