csv_migration 0.0.1 → 0.0.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 +4 -4
- data/lib/csv_migration.rb +7 -7
- 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: 00f06e4a49f53bb66702884ad4ab06c5fa41bfb15c69e1eb6d637bf4fb9d0281
|
4
|
+
data.tar.gz: 6e667978527a2a0b55899315d3b1d98b4aa0e05e52eacdec961ae1efd67e2cf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe20b127b0ccf7fa5cad36d40e417bc211bd14ae9a93b8128f2e912ffcadbcaac7950f006dd3dd56fd6d4d024f1bd7694809c181bfc84e361696248da3084ead
|
7
|
+
data.tar.gz: bc9aca62d52e52f2d2be63a35e5acfc1edfca3aa63a6e904e1daecb27a8989ebcdb9b2e43fd45a25bc3a908c0923dc35fc15c0460d0255e86769ed037512f2a9
|
data/lib/csv_migration.rb
CHANGED
@@ -11,7 +11,7 @@ class CsvMigration
|
|
11
11
|
|
12
12
|
@file_name = @file_name_csv.split('.csv').first
|
13
13
|
|
14
|
-
# File for export correct data from base file
|
14
|
+
# File for export correct data from the base file
|
15
15
|
@correct_file_data_csv = File.expand_path("v_parser_correct_#{@file_name}.csv")
|
16
16
|
@errors_log = File.expand_path("v_parser_errors_#{@file_name}.log")
|
17
17
|
@duplicates_log = File.expand_path("v_parser_duplicates_#{@file_name}.log")
|
@@ -56,7 +56,7 @@ class CsvMigration
|
|
56
56
|
# Key: column name in the csv file
|
57
57
|
# Value:
|
58
58
|
# field: a field name of a table in a DB (symbol)
|
59
|
-
# require: a field should be
|
59
|
+
# require: a field should not be empty (true/false)
|
60
60
|
# replace: need to use @replace_dict ( @replace_dict = { 'what need replace' => 'replace to this' } ) (true/false)
|
61
61
|
# prefix: need to add value as a prefix from a field header name (header name from CSV file) (string)
|
62
62
|
# validate: callback method which necessary call for validating a specific format (symbol)
|
@@ -100,7 +100,7 @@ class CsvMigration
|
|
100
100
|
|
101
101
|
@parsed_data << { id: @line_num - 1 }.merge(records)
|
102
102
|
|
103
|
-
puts "
|
103
|
+
puts "Parse left #{@count_file_lines - @line_num} lines"
|
104
104
|
@line_num += 1
|
105
105
|
@counter_good_records += 1
|
106
106
|
end
|
@@ -120,7 +120,7 @@ class CsvMigration
|
|
120
120
|
puts "Bad records: #{@errors.values.sum}"
|
121
121
|
puts "Duplicate records: #{@counter_duplicates}"
|
122
122
|
puts "Duplicates more than one field: #{double_duplicates}" if double_duplicates.positive?
|
123
|
-
puts "
|
123
|
+
puts "Successfully parsed records: #{@parsed_data.size}"
|
124
124
|
|
125
125
|
error_actions if !@errors.values.sum.zero? || !@counter_duplicates.zero?
|
126
126
|
|
@@ -201,7 +201,7 @@ class CsvMigration
|
|
201
201
|
# @param [Object] value hash data from dict
|
202
202
|
def check_field(data, key, value)
|
203
203
|
if @parsing_file_header.find_index(key).nil?
|
204
|
-
puts "Please, correct settings in the @ref_csv_head_from_file hash. Key #{key}
|
204
|
+
puts "Please, correct settings in the @ref_csv_head_from_file hash. Key #{key} has not been found in the header of #{@file_name_csv} file!"
|
205
205
|
exit
|
206
206
|
end
|
207
207
|
|
@@ -447,11 +447,11 @@ class CsvMigration
|
|
447
447
|
def add_record_to_db(_record)
|
448
448
|
raise 'You should make realization callback method add_record_to_db(record)'
|
449
449
|
|
450
|
-
# Search data of model if
|
450
|
+
# Search data of model if is necessary
|
451
451
|
# user = User.find_by(email: record[:email].downcase)
|
452
452
|
#
|
453
453
|
# if user.nil?
|
454
|
-
# save_error(record, "User
|
454
|
+
# save_error(record, "User has not been found in the DB by email")
|
455
455
|
# next
|
456
456
|
# end
|
457
457
|
end
|