datashift 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.14.0
1
+ 0.15.0
@@ -117,6 +117,7 @@ end
117
117
  DataShift::require_libraries
118
118
 
119
119
  require 'datashift/guards'
120
+ require 'datashift/logging'
120
121
  require 'datashift/method_detail'
121
122
  require 'datashift/method_dictionary'
122
123
  require 'datashift/method_mapper'
@@ -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?
@@ -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
- #puts "DEBUG : VALUE TYPE [#{value.class.name.include?(operator.classify)}] [#{ModelMapper.class_from_string(value.class.name)}]" unless(value.is_a?(Array))
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(value.is_a?(Array) || value.class.name.include?(operator.classify))
100
- record.send(operator) << value
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 #{value.class} - Not expected type for has_many #{operator} - cannot assign"
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(value.is_a?(method_detail.operator_class))
109
- record.send(operator + '=', value)
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
- puts "ERROR: #{e.inspect}"
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
@@ -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 image files (based on file extensions) from supplied path.
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
- puts e.inspect
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
@@ -17,7 +17,7 @@
17
17
  # bundle exec thor help datashift:generate:excel
18
18
  #
19
19
  require 'datashift'
20
- require 'excel_generator'
20
+ require 'generators/excel_generator'
21
21
 
22
22
  # Note, not DataShift, case sensitive, create namespace for command line : datashift
23
23
  module Datashift
@@ -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.14.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-05-19 00:00:00.000000000 Z
12
+ date: 2014-06-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spreadsheet