csv_pirate 4.0.10 → 4.0.11
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/CHANGELOG +7 -0
- data/VERSION.yml +2 -2
- data/csv_pirate.gemspec +1 -1
- data/lib/csv_pirate.rb +50 -18
- data/lib/ninth_bit/pirate_ship.rb +3 -3
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
Version 4.0.11 2010-03-08
|
2
|
+
- PirateShip now respects CsvPirate.parlay setting instead of always overwriting it.
|
3
|
+
- CsvPirate importing actually works now
|
4
|
+
|
5
|
+
Version 4.0.8, 4.0.9, 4.0.10 2010-03-08
|
6
|
+
- Trying to get a gemcutter push to work
|
7
|
+
|
1
8
|
Version 4.0.7 2010-03-08
|
2
9
|
- Fixed bug preventing use with rake db: tasks (create, reset, etc)
|
3
10
|
|
data/VERSION.yml
CHANGED
data/csv_pirate.gemspec
CHANGED
data/lib/csv_pirate.rb
CHANGED
@@ -342,50 +342,44 @@ class CsvPirate
|
|
342
342
|
buccaneers << self.grub.create(data_hash)
|
343
343
|
else
|
344
344
|
if permanence[:find_or_new]
|
345
|
-
obj = self.
|
345
|
+
obj = self.send_aye(data_hash, permanence[:find_or_new])
|
346
346
|
buccaneers << self.grub.new(data_hash) if obj.nil?
|
347
347
|
elsif permanence[:find_or_save]
|
348
|
-
obj = self.
|
348
|
+
obj = self.send_aye(data_hash, permanence[:find_or_save])
|
349
349
|
if obj.nil?
|
350
350
|
obj = self.grub.new(data_hash)
|
351
351
|
obj.save(false) if obj.respond_to?(:save)
|
352
352
|
end
|
353
353
|
buccaneers << obj
|
354
354
|
elsif permanence[:find_or_create]
|
355
|
-
obj = self.
|
355
|
+
obj = self.send_aye(data_hash, permanence[:find_or_create])
|
356
|
+
if obj.nil?
|
357
|
+
self.grub.create(data_hash)
|
358
|
+
end
|
356
359
|
buccaneers << obj
|
357
360
|
elsif permanence[:update_or_new]
|
358
|
-
obj = self.
|
361
|
+
obj = self.send_aye(data_hash, permanence[:update_or_new])
|
359
362
|
if obj.nil?
|
360
363
|
obj = self.grub.new(data_hash)
|
361
364
|
else
|
362
|
-
|
363
|
-
obj.send("#{k}=".to_sym, v)
|
364
|
-
obj.save(false)
|
365
|
-
end
|
365
|
+
self.save_object(obj, data_hash)
|
366
366
|
end
|
367
367
|
buccaneers << obj
|
368
368
|
elsif permanence[:update_or_save]
|
369
|
-
obj = self.
|
369
|
+
obj = self.send_aye(data_hash, permanence[:update_or_save])
|
370
370
|
if obj.nil?
|
371
371
|
obj = self.grub.new(data_hash)
|
372
372
|
obj.save(false)
|
373
373
|
else
|
374
|
-
|
375
|
-
obj.send("#{k}=".to_sym, v)
|
376
|
-
obj.save(false)
|
377
|
-
end
|
374
|
+
self.save_object(obj, data_hash)
|
378
375
|
end
|
379
376
|
buccaneers << obj
|
380
377
|
elsif permanence[:update_or_create]
|
381
|
-
obj = self.
|
378
|
+
obj = self.send_aye(data_hash, permanence[:update_or_create])
|
382
379
|
if obj.nil?
|
383
380
|
obj = self.grub.create(data_hash)
|
384
381
|
else
|
385
|
-
|
386
|
-
obj.send("#{k}=".to_sym, v)
|
387
|
-
obj.save(false)
|
388
|
-
end
|
382
|
+
self.save_object(obj, data_hash)
|
389
383
|
end
|
390
384
|
buccaneers << obj
|
391
385
|
end
|
@@ -394,6 +388,44 @@ class CsvPirate
|
|
394
388
|
buccaneers
|
395
389
|
end
|
396
390
|
|
391
|
+
def save_object(obj, data_hash)
|
392
|
+
data_hash.each do |k,v|
|
393
|
+
obj.send("#{k}=".to_sym, v)
|
394
|
+
end
|
395
|
+
unless obj.save(false)
|
396
|
+
puts "Save Failed: #{obj.inspect}" if CsvPirate.parlance(1)
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
def send_aye(data_hash, columns)
|
401
|
+
obj = self.grub.send(self.find_aye(columns), self.find_aye_arr(data_hash, columns))
|
402
|
+
if obj
|
403
|
+
puts "#{self.grub}.#{find_aye(columns)}(#{self.find_aye_arr(data_hash, columns).inspect}): found id = #{obj.id}" if CsvPirate.parlance(2)
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
def find_aye(columns)
|
408
|
+
"find_by_#{columns.join('_and_')}".to_sym
|
409
|
+
end
|
410
|
+
|
411
|
+
def find_aye_arr(data_hash, columns)
|
412
|
+
columns.map do |col|
|
413
|
+
data_hash[col.to_s]
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
def data_hash_from_row(row, exclude_id = true, exclude_timestamps = true, example = nil)
|
418
|
+
plunder = {}
|
419
|
+
my_booty = self.booty.reject {|x| x.is_a?(Hash)}
|
420
|
+
my_booty = exclude_id ? my_booty.reject {|x| a = x.to_sym; [:id, :ID,:dbid, :DBID, :db_id, :DB_ID].include?(a)} : self.booty
|
421
|
+
my_booty = exclude_timestamps ? my_booty.reject {|x| a = x.to_sym; [:created_at, :updated_at, :created_on, :updated_on].include?(a)} : self.booty
|
422
|
+
my_booty = my_booty.reject {|x| !example.respond_to?("#{x}=".to_sym)} unless example.nil?
|
423
|
+
my_booty.each do |method|
|
424
|
+
plunder = plunder.merge({method => row[self.pinnacle[self.booty.index(method)]]})
|
425
|
+
end
|
426
|
+
plunder
|
427
|
+
end
|
428
|
+
|
397
429
|
def data_hash_from_row(row, exclude_id = true, exclude_timestamps = true, example = nil)
|
398
430
|
data_hash = {}
|
399
431
|
my_booty = self.booty.reject {|x| x.is_a?(Hash)}
|
@@ -57,8 +57,8 @@ module NinthBit
|
|
57
57
|
begin
|
58
58
|
defined?(ActiveRecord) && ActiveRecord::Base.connected? ?
|
59
59
|
self.respond_to?(:table_name) && ActiveRecord::Base.connection.tables.include?(self.table_name) :
|
60
|
-
|
61
|
-
|
60
|
+
self.respond_to?(:column_names)
|
61
|
+
#The only error that occurs here is when ActiveRecord checks for the table but the database isn't setup yet.
|
62
62
|
#It was preventing rake db:create from working.
|
63
63
|
rescue
|
64
64
|
puts "csv_pirate: failed to connect to database, or table missing"
|
@@ -134,7 +134,7 @@ module NinthBit
|
|
134
134
|
protected
|
135
135
|
|
136
136
|
def piratey_args(args = {})
|
137
|
-
CsvPirate.parlay
|
137
|
+
CsvPirate.parlay ||= args[:parlay] || self.piratey_options[:parlay]
|
138
138
|
return { :chart => args[:chart] || self.piratey_options[:chart],
|
139
139
|
:aft => args[:aft] || self.piratey_options[:aft],
|
140
140
|
:gibbet => args[:gibbet] || self.piratey_options[:gibbet],
|