csv_step_importer 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +66 -6
- data/lib/csv_step_importer/model/importable_model.rb +2 -1
- data/lib/csv_step_importer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38a5dd24101512b6117a0d8d33020b52ccedbeb816b9b49a64473471b471bd64
|
4
|
+
data.tar.gz: 1c2bccce9e7945daba6bd90ac18aa68a77f14b401f8c1af6bc0f8d619d94dca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe1abd4a1c0078c4af1e629e769612c8dce19a718522607e692b3d323ff681cbc83335073e4924d94f2aa6fcdccbe045e638febea102d15625adb742aa65f307
|
7
|
+
data.tar.gz: a63422a10246541cfa0537538c625c51c55746bfa1730ad718bd2895f6955e87ef8893de3d90cf687d8eb0d9cc25794bb44cf919d21aa1585add255b97f053f5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# csv_step_importer
|
2
2
|
|
3
|
-
|
3
|
+
A library to validate, speed up and organize bulk insertion of complex CSV data, including multi-table data.
|
4
4
|
|
5
|
-
|
5
|
+
It depends on
|
6
|
+
|
7
|
+
- [zdennis/activerecord-import](https://github.com/zdennis/activerecord-import)
|
8
|
+
- [GitHub - tilo/smarter_csv](https://github.com/tilo/smarter_csv)
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
@@ -22,7 +25,64 @@ Or install it yourself as:
|
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
25
|
-
|
28
|
+
### Hello world
|
29
|
+
|
30
|
+
Create a new rails application:
|
31
|
+
|
32
|
+
```shell
|
33
|
+
rails new currency_wiki --database=mysql
|
34
|
+
cd currency_wiki
|
35
|
+
echo "gem 'csv_step_importer'" >> Gemfile
|
36
|
+
bundle install
|
37
|
+
rails g model currency code:string:uniq name:string
|
38
|
+
rails db:create db:migrate
|
39
|
+
```
|
40
|
+
|
41
|
+
Then edit the model like this:
|
42
|
+
|
43
|
+
/app/models/currency.rb
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
class Currency < ApplicationRecord
|
47
|
+
class ImportableModel < CSVStepImporter::Model::ImportableModel
|
48
|
+
# The model to be updated
|
49
|
+
def model_class
|
50
|
+
::Currency
|
51
|
+
end
|
52
|
+
|
53
|
+
def columns
|
54
|
+
[:code, :name, :created_at, :updated_at]
|
55
|
+
end
|
56
|
+
|
57
|
+
def on_duplicate_key_update
|
58
|
+
[:name, :updated_at]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
|
65
|
+
Create a test CSV file and upload it
|
66
|
+
|
67
|
+
```shell
|
68
|
+
rails c
|
69
|
+
```
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
File.open("currencies.csv", "w") do |file|
|
73
|
+
file.write(<<~CSV)
|
74
|
+
Name,Code
|
75
|
+
Euro,EUR
|
76
|
+
United States dollar,USD
|
77
|
+
Japanese Yen,JPY
|
78
|
+
CSV
|
79
|
+
end
|
80
|
+
|
81
|
+
CSVStepImporter::File.new(path: 'currencies.csv', processor_classes: [Currency::ImportableModel]).save
|
82
|
+
|
83
|
+
puts Currency.all.to_yaml
|
84
|
+
```
|
85
|
+
|
26
86
|
|
27
87
|
## Development
|
28
88
|
|
@@ -32,7 +92,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
92
|
|
33
93
|
## Contributing
|
34
94
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
95
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fruwe/csv_step_importer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
96
|
|
37
97
|
## License
|
38
98
|
|
@@ -40,4 +100,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
100
|
|
41
101
|
## Code of Conduct
|
42
102
|
|
43
|
-
Everyone interacting in the CSVStepImporter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
103
|
+
Everyone interacting in the CSVStepImporter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fruwe/csv_step_importer/blob/master/CODE_OF_CONDUCT.md).
|
@@ -19,7 +19,8 @@ module CSVStepImporter
|
|
19
19
|
|
20
20
|
# set to nil in order to deactivate
|
21
21
|
def reflector_class
|
22
|
-
CSVStepImporter::Model::Reflector
|
22
|
+
# in order to enable reflections return reflector class: CSVStepImporter::Model::Reflector
|
23
|
+
nil
|
23
24
|
end
|
24
25
|
|
25
26
|
# example: env[:company].company_users
|