datashift 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -20
- data/VERSION +1 -1
- data/datashift.gemspec +4 -2
- data/lib/loaders/csv_loader.rb +6 -0
- data/lib/loaders/excel_loader.rb +21 -14
- data/lib/loaders/loader_base.rb +16 -3
- data/lib/loaders/reporter.rb +3 -2
- metadata +2 -2
data/Rakefile
CHANGED
@@ -29,26 +29,6 @@ $:.unshift lib unless $:.include?(lib)
|
|
29
29
|
|
30
30
|
require 'datashift'
|
31
31
|
|
32
|
-
require 'jeweler'
|
33
|
-
Jeweler::Tasks.new do |gem|
|
34
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
35
|
-
gem.name = DataShift.gem_name
|
36
|
-
gem.homepage = "http://github.com/autotelik/datashift"
|
37
|
-
gem.license = "MIT"
|
38
|
-
gem.summary = %Q{ Shift data betwen Excel/CSV and any Ruby app}
|
39
|
-
gem.description = %Q{Comprehensive tools to import/export between Excel/CSV and ActiveRecord databases, Rails apps, and any Ruby project.}
|
40
|
-
gem.email = "rubygems@autotelik.co.uk"
|
41
|
-
gem.authors = ["Thomas Statter"]
|
42
|
-
# dependencies defined in Gemfile
|
43
|
-
gem.files.exclude ['sandbox/**']
|
44
|
-
gem.files.exclude ['spec/**/*']
|
45
|
-
|
46
|
-
gem.add_dependency 'spreadsheet'
|
47
|
-
gem.add_dependency 'rubyzip'
|
48
|
-
|
49
|
-
end
|
50
|
-
Jeweler::RubygemsDotOrgTasks.new
|
51
|
-
|
52
32
|
require 'rake/testtask'
|
53
33
|
Rake::TestTask.new(:test) do |test|
|
54
34
|
test.libs << 'lib' << 'test'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.12.
|
1
|
+
0.12.1
|
data/datashift.gemspec
CHANGED
@@ -2,11 +2,13 @@ require 'rake'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "datashift"
|
5
|
-
s.version = "0.12.
|
5
|
+
s.version = "0.12.1"
|
6
|
+
s.date = Date.today.to_s
|
6
7
|
|
7
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
|
+
|
8
10
|
s.authors = ["Thomas Statter"]
|
9
|
-
|
11
|
+
|
10
12
|
s.description = "Comprehensive tools to import/export between Excel/CSV and ActiveRecord databases, Rails apps, and any Ruby project."
|
11
13
|
s.email = "rubygems@autotelik.co.uk"
|
12
14
|
s.extra_rdoc_files = [
|
data/lib/loaders/csv_loader.rb
CHANGED
@@ -83,6 +83,12 @@ module DataShift
|
|
83
83
|
rescue => e
|
84
84
|
failure( row, true )
|
85
85
|
logger.error "Failed to process row [#{i}] (#{@current_row})"
|
86
|
+
|
87
|
+
if(verbose)
|
88
|
+
puts "Failed to process row [#{i}] (#{@current_row})"
|
89
|
+
puts e.inspect
|
90
|
+
end
|
91
|
+
|
86
92
|
# don't forget to reset the load object
|
87
93
|
new_load_object
|
88
94
|
next
|
data/lib/loaders/excel_loader.rb
CHANGED
@@ -42,7 +42,6 @@ module DataShift
|
|
42
42
|
|
43
43
|
@excel.open(file_name)
|
44
44
|
|
45
|
-
#if(options[:verbose])
|
46
45
|
puts "\n\n\nLoading from Excel file: #{file_name}"
|
47
46
|
|
48
47
|
sheet_number = options[:sheet_number] || 0
|
@@ -72,7 +71,8 @@ module DataShift
|
|
72
71
|
# For example if model has an attribute 'price' will map columns called Price, price, PRICE etc to this attribute
|
73
72
|
populate_method_mapper_from_headers( @headers, options )
|
74
73
|
|
75
|
-
|
74
|
+
# currently pointless num_rows rubbish i.e inaccurate!
|
75
|
+
#logger.info "Excel Loader processing #{@sheet.num_rows} rows"
|
76
76
|
|
77
77
|
@reporter.reset
|
78
78
|
|
@@ -129,7 +129,14 @@ module DataShift
|
|
129
129
|
@reporter.processed_object_count += 1
|
130
130
|
|
131
131
|
failure(@current_row, true)
|
132
|
+
|
133
|
+
if(verbose)
|
134
|
+
puts "Failed to process row [#{i}] (#{@current_row})"
|
135
|
+
puts e.inspect
|
136
|
+
end
|
137
|
+
|
132
138
|
logger.error "Failed to process row [#{i}] (#{@current_row})"
|
139
|
+
|
133
140
|
# don't forget to reset the load object
|
134
141
|
new_load_object
|
135
142
|
next
|
@@ -148,25 +155,25 @@ module DataShift
|
|
148
155
|
logger.error load_object.errors.inspect if(load_object)
|
149
156
|
else
|
150
157
|
logger.info "Row #{@current_row} succesfully SAVED : ID #{load_object.id}"
|
151
|
-
|
158
|
+
@reporter.add_loaded_object(@load_object)
|
152
159
|
end
|
153
160
|
|
154
161
|
# don't forget to reset the object or we'll update rather than create
|
155
162
|
new_load_object
|
156
163
|
|
157
164
|
end
|
158
|
-
|
159
|
-
|
160
|
-
|
165
|
+
|
166
|
+
if(options[:dummy])
|
167
|
+
puts "Excel loading stage complete - Dummy run so Rolling Back."
|
168
|
+
raise ActiveRecord::Rollback # Don't actually create/upload to DB if we are doing dummy run
|
169
|
+
end
|
170
|
+
|
171
|
+
end # TRANSACTION N.B ActiveRecord::Rollback does not propagate outside of the containing transaction block
|
161
172
|
|
162
|
-
rescue => e
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
else
|
167
|
-
raise e
|
168
|
-
end
|
169
|
-
ensure
|
173
|
+
rescue => e
|
174
|
+
puts "ERROR: Excel loading failed : #{e.inspect}"
|
175
|
+
raise e
|
176
|
+
ensure
|
170
177
|
report
|
171
178
|
end
|
172
179
|
|
data/lib/loaders/loader_base.rb
CHANGED
@@ -45,6 +45,7 @@ module DataShift
|
|
45
45
|
#
|
46
46
|
# :reload : Force load of the method dictionary for object_class even if already loaded
|
47
47
|
# :instance_methods : Include setter/delegate style instance methods for assignment, as well as AR columns
|
48
|
+
# :verbose : Verboise logging and to STDOUT
|
48
49
|
#
|
49
50
|
def initialize(object_class, find_operators = true, object = nil, options = {})
|
50
51
|
@load_object_class = object_class
|
@@ -63,6 +64,8 @@ module DataShift
|
|
63
64
|
@config = options.dup # clone can cause issues like 'can't modify frozen hash'
|
64
65
|
|
65
66
|
@verbose = @config[:verbose]
|
67
|
+
|
68
|
+
puts "Verbose Mode" if(verbose)
|
66
69
|
@headers = []
|
67
70
|
|
68
71
|
@default_data_objects ||= {}
|
@@ -407,7 +410,7 @@ module DataShift
|
|
407
410
|
def save
|
408
411
|
return unless( @load_object )
|
409
412
|
|
410
|
-
|
413
|
+
puts "DEBUG: SAVING #{@load_object.class} : #{@load_object.inspect}" if(verbose)
|
411
414
|
begin
|
412
415
|
return @load_object.save
|
413
416
|
rescue => e
|
@@ -515,9 +518,19 @@ module DataShift
|
|
515
518
|
|
516
519
|
private
|
517
520
|
|
521
|
+
# This method usually called during processing to avoid errors with associations like
|
522
|
+
# <ActiveRecord::RecordNotSaved: You cannot call create unless the parent is saved>
|
523
|
+
# If the object is still invalid at this point probably indicates compulsory
|
524
|
+
# columns on model have not been processed before associations on that model
|
525
|
+
# TODO smart ordering of columns dynamically ourselves rather than relying on incoming data order
|
518
526
|
def save_if_new
|
519
|
-
|
520
|
-
|
527
|
+
return unless(load_object.new_record?)
|
528
|
+
|
529
|
+
if(load_object.valid?)
|
530
|
+
save
|
531
|
+
else
|
532
|
+
puts "Cannot Save - Invalid #{load_object.class} - #{load_object.errors.full_messages}" if(verbose)
|
533
|
+
end
|
521
534
|
end
|
522
535
|
|
523
536
|
end
|
data/lib/loaders/reporter.rb
CHANGED
@@ -35,8 +35,9 @@ module DataShift
|
|
35
35
|
def report
|
36
36
|
loaded_objects.compact! if(loaded_objects)
|
37
37
|
|
38
|
-
puts "
|
39
|
-
puts "
|
38
|
+
puts "\nProcessing Summary Report"
|
39
|
+
puts ">>>>>>>>>>>>>>>>>>>>>>>>>\n"
|
40
|
+
puts "Processed total of #{processed_object_count} #{processed_object_count > 1 ? 'entries' : 'entry'}"
|
40
41
|
puts "#{loaded_objects.size} objects were succesfully processed."
|
41
42
|
|
42
43
|
puts "There were NO failures." if failed_objects.empty?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datashift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spreadsheet
|