datashift 0.14.0 → 0.15.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.
- data/VERSION +1 -1
- data/lib/datashift.rb +1 -0
- data/lib/datashift/method_detail.rb +1 -0
- data/lib/datashift/populator.rb +15 -8
- data/lib/loaders/excel_loader.rb +3 -0
- data/lib/loaders/paperclip/datashift_paperclip.rb +2 -2
- data/lib/thor/generate.thor +1 -1
- data/spec/excel_loader_spec.rb +3 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.15.0
|
data/lib/datashift.rb
CHANGED
@@ -131,6 +131,7 @@ module DataShift
|
|
131
131
|
break
|
132
132
|
end
|
133
133
|
rescue => e
|
134
|
+
logger.error "Failed to match belongs_to association #{value}"
|
134
135
|
puts "ERROR: #{e.inspect}"
|
135
136
|
if(x == Populator::insistent_method_list.last)
|
136
137
|
raise "I'm sorry I have failed to assign [#{value}] to #{@assignment}" unless value.nil?
|
data/lib/datashift/populator.rb
CHANGED
@@ -75,8 +75,14 @@ module DataShift
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def assign(method_detail, record, value )
|
78
|
-
|
78
|
+
|
79
79
|
@current_value = value
|
80
|
+
|
81
|
+
# Rails 4 - not an array any more
|
82
|
+
if( value.is_a? ActiveRecord::Relation )
|
83
|
+
logger.warn("Relation passed rather than value #{value.inspect}")
|
84
|
+
@current_value = value.to_a
|
85
|
+
end
|
80
86
|
|
81
87
|
# logger.info("WARNING nil value supplied for Column [#{@name}]") if(@current_value.nil?)
|
82
88
|
|
@@ -89,24 +95,24 @@ module DataShift
|
|
89
95
|
|
90
96
|
elsif( method_detail.operator_for(:has_many) )
|
91
97
|
|
92
|
-
|
98
|
+
puts "DEBUG : VALUE TYPE [#{value.class.name.include?(operator.classify)}] [#{ModelMapper.class_from_string(value.class.name)}]" unless(value.is_a?(Array))
|
93
99
|
|
94
100
|
# The include? check is best I can come up with right now .. to handle module/namespaces
|
95
101
|
# TODO - can we determine the real class type of an association
|
96
102
|
# e.g given a association taxons, which operator.classify gives us Taxon, but actually it's Spree::Taxon
|
97
103
|
# so how do we get from 'taxons' to Spree::Taxons ? .. check if further info in reflect_on_all_associations
|
98
104
|
|
99
|
-
if(
|
100
|
-
record.send(operator) <<
|
105
|
+
if(@current_value.is_a?(Array) || @current_value.class.name.include?(operator.classify))
|
106
|
+
record.send(operator) << @current_value
|
101
107
|
else
|
102
|
-
puts "ERROR #{
|
108
|
+
puts "ERROR #{@current_value.class} - Not expected type for has_many #{operator} - cannot assign"
|
103
109
|
end
|
104
110
|
|
105
111
|
elsif( method_detail.operator_for(:has_one) )
|
106
112
|
|
107
113
|
#puts "DEBUG : HAS_MANY : #{@name} : #{operator}(#{operator_class}) - Lookup #{@current_value} in DB"
|
108
|
-
if(
|
109
|
-
record.send(operator + '=',
|
114
|
+
if(@current_value.is_a?(method_detail.operator_class))
|
115
|
+
record.send(operator + '=', @current_value)
|
110
116
|
else
|
111
117
|
logger.error("ERROR #{value.class} - Not expected type for has_one #{operator} - cannot assign")
|
112
118
|
# TODO - Not expected type - maybe try to look it up somehow ?"
|
@@ -127,6 +133,7 @@ module DataShift
|
|
127
133
|
insistent_assignment(record, @current_value, operator)
|
128
134
|
else
|
129
135
|
puts "WARNING: No assignment possible on #{record.inspect} using [#{operator}]"
|
136
|
+
logger.error("WARNING: No assignment possible on #{record.inspect} using [#{operator}]")
|
130
137
|
end
|
131
138
|
end
|
132
139
|
|
@@ -171,7 +178,7 @@ module DataShift
|
|
171
178
|
break
|
172
179
|
end
|
173
180
|
rescue => e
|
174
|
-
|
181
|
+
logger.error("Attempt to find associated object failed for #{method_detail}")
|
175
182
|
if(x == Populator::insistent_method_list.last)
|
176
183
|
raise "Populator failed to assign [#{value}] via moperator #{operator}" unless value.nil?
|
177
184
|
end
|
data/lib/loaders/excel_loader.rb
CHANGED
@@ -198,6 +198,9 @@ module DataShift
|
|
198
198
|
|
199
199
|
|
200
200
|
def perform_load( file_name, options = {} )
|
201
|
+
|
202
|
+
logger.info "Starting bulk load from Excel : #{file_name}"
|
203
|
+
|
201
204
|
perform_excel_load( file_name, options )
|
202
205
|
|
203
206
|
puts "Excel loading stage complete - #{loaded_count} rows added."
|
@@ -18,7 +18,7 @@ module DataShift
|
|
18
18
|
|
19
19
|
attr_accessor :attachment
|
20
20
|
|
21
|
-
# Get all
|
21
|
+
# Get all files (based on file extensions) from supplied path.
|
22
22
|
# Options :
|
23
23
|
# :glob : The glob to use to find files
|
24
24
|
# => :recursive : Descend tree looking for files rather than just supplied path
|
@@ -86,7 +86,7 @@ module DataShift
|
|
86
86
|
begin
|
87
87
|
@attachment = klass.new(paperclip_attributes, :without_protection => true)
|
88
88
|
rescue => e
|
89
|
-
|
89
|
+
logger.error( e.backtrace)
|
90
90
|
logger.error("Failed to create PaperClip Attachment : #{e.inspect}")
|
91
91
|
raise CreateAttachmentFailed.new("Failed to create PaperClip Attachment from : #{attachment_path}")
|
92
92
|
ensure
|
data/lib/thor/generate.thor
CHANGED
data/spec/excel_loader_spec.rb
CHANGED
@@ -52,9 +52,9 @@ describe 'Excel Loader' do
|
|
52
52
|
loader.loaded_count.should == (Project.count - count)
|
53
53
|
end
|
54
54
|
|
55
|
-
it "should process multiple associationss from single column" do
|
56
|
-
|
55
|
+
it "should process multiple associationss from single column", :fail => true do
|
57
56
|
|
57
|
+
|
58
58
|
DataShift::MethodDictionary.find_operators( Category )
|
59
59
|
|
60
60
|
DataShift::MethodDictionary.build_method_details( Category )
|
@@ -64,6 +64,7 @@ describe 'Excel Loader' do
|
|
64
64
|
|
65
65
|
loader = ExcelLoader.new(Project)
|
66
66
|
|
67
|
+
|
67
68
|
loader.perform_load( ifixture_file('ProjectsSingleCategories.xls') )
|
68
69
|
|
69
70
|
loader.loaded_count.should be > 3
|
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.
|
4
|
+
version: 0.15.0
|
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: 2014-
|
12
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spreadsheet
|