csv_importer 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.
@@ -34,6 +34,11 @@ For use with ActiveRecord objects you can provide an argument to call save on ev
34
34
 
35
35
  products = importer.object(true)
36
36
 
37
+ The attributes of ActiveRecord objects are assigned using update_attributes for increased security.
38
+
39
+ Beware, that if the model is not an ActiveRecord model mass assigning attributes by CSV column name might impose a security risk if you don't know the exact names of the CSV columns.
40
+
41
+ In a next release a stripped down version of active records "attr_accessible" will be bundled with the gem.
37
42
 
38
43
  == REQUIREMENTS:
39
44
 
@@ -1,5 +1,5 @@
1
1
  module CSVImporter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  require 'csv'
4
4
 
5
5
 
@@ -19,14 +19,21 @@ module CSVImporter
19
19
  def objects(save=false)
20
20
  return @objects if !@objects.nil?
21
21
  @objects = Array.new if @object.nil?
22
+
22
23
  first = true
23
24
  @reader.each do |row|
24
25
  #TODO: Ruby 1.9 has header option would be nicer instead of this hack.
25
26
  if !first
26
27
  object = @klass.new
28
+ active_record = object.respond_to?(:update_attributes)
29
+ attribute_hash = {} if active_record
27
30
  @columns.each_pair do |column, row_number|
28
- object.send("#{column}=", row[row_number].strip)
31
+ value = row[row_number]
32
+ value = value.strip if !value.nil?
33
+ object.send("#{column}=", value) if !active_record
34
+ attribute_hash[column] = value if active_record
29
35
  end
36
+ object.attributes = attribute_hash if active_record
30
37
  object.save if save
31
38
  @objects << object
32
39
  else
@@ -1,6 +1,14 @@
1
1
  Description;Brand;SellPrice;SalePrice;Image;Category;ArticleCode
2
- SINGLE JERSEY L.S R;PME Jeans; 59.95; 59.95;http://www.example.com/images/JTS91573.JPG;T-shirts;JTS91573
3
- MONTANA L.SL. GRAND;PME legend; 59.95; 59.95;http://www.example.com/images/PTS88510.JPG;T-shirts;PTS88510
4
- CO DOUBLE JERSEY, 1;Cast Iron; 29.95; 29.95;http://www.example.com/images/CAC91101.JPG;Belts/ Keyholders;CAC91101
5
- PLAYER L.SLV. VEST;Cast Iron; 99.95; 99.95;http://www.example.com/images/CKW91406.JPG;Knitwear;CKW91406
6
- SLUBOR L.SL POLO;Cast Iron; 79.95; 79.95;http://www.example.com/images/CPS91301.JPG;Polo l.sl;CPS91301
2
+ SINGLE JERSEY L.S R;PME Jeans; 59.95; 59.95;http://www.softwear.nl/ism/bouchier/images/JTS91573.JPG;T-shirts;JTS91573
3
+ MONTANA L.SL. GRAND;PME legend; 59.95; 59.95;http://www.softwear.nl/ism/bouchier/images/PTS88510.JPG;T-shirts;PTS88510
4
+ CO DOUBLE JERSEY, 1;Cast Iron; 29.95; 29.95;http://www.softwear.nl/ism/bouchier/images/CAC91101.JPG;Belts/ Keyholders;CAC91101
5
+ PLAYER L.SLV. VEST;Cast Iron; 99.95; 99.95;http://www.softwear.nl/ism/bouchier/images/CKW91406.JPG;Knitwear;CKW91406
6
+ SLUBOR L.SL POLO;Cast Iron; 79.95; 79.95;http://www.softwear.nl/ism/bouchier/images/CPS91301.JPG;Polo l.sl;CPS91301
7
+ BEAR CLAW FLOWER -;Cast Iron; 89.95; 89.95;http://www.softwear.nl/ism/bouchier/images/CSI91601.JPG;Shirts;CSI91601
8
+ KHENSU LSE - MULTI;Cast Iron; 129.95; 129.95;http://www.softwear.nl/ism/bouchier/images/CTR91202-960.JPG;Pants;CTR91202-960
9
+ NYLON FLIGHT BOMBER;PME legend; 179.95; 179.95;http://www.softwear.nl/ism/bouchier/images/JA86112.JPG;Jackets;JA86112
10
+ RATON LONG JACKET;Vanguard; 239.95; 239.95;http://www.softwear.nl/ism/bouchier/images/VJA86149.JPG;Jackets;VJA86149
11
+ OXFORD PANT, COTTON;Vanguard; 89.95; 89.95;http://www.softwear.nl/ism/bouchier/images/VTR86422-739.JPG;Pants;VTR86422-739
12
+ MERIDIAN S.SL R-NEC;Vanguard; 49.95; 49.95;http://www.softwear.nl/ism/bouchier/images/VTSS86301.JPG;T-shirts;VTSS86301
13
+ ;PME legend; 24.95; 24.95;http://www.softwear.nl/ism/bouchier/images/PAC91002.JPG;Belts/ Keyholders;PAC91002
14
+ COTTON PLAITED V-NE;PME legend; 89.95; 89.95;http://www.softwear.nl/ism/bouchier/images/PKW91339.JPG;Knitwear;PKW91339
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sparkboxx
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-04 00:00:00 +01:00
12
+ date: 2009-11-05 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency