acts_as_importable 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,6 +51,17 @@ Another example of the method above:
51
51
  self.category_id = category.id if category
52
52
  end
53
53
 
54
+ === Modify data before import:
55
+
56
+ class Product
57
+ acts_as_importable :import_fields => ["name", "price"], :before_import => :modify_data
58
+ self.modify_data data_row
59
+ data_row[0] = "Modified data"
60
+ end
61
+ end
62
+
63
+ If before_import is supplied, the given method (in this case 'modify_data') will be called on each row. Current row from csv file is passed to the given method as parameter, which can be modified here before object is created. The 'data_row' parameter is an array which represent a row in csv file.
64
+
54
65
  ==== Customizing the export fields:
55
66
 
56
67
  You can specify a different list of fields to export if you want them to be different from the import fields e.g.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.4
1
+ 0.4.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_importable}
8
- s.version = "0.4.4"
8
+ s.version = "0.4.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jagdeep Singh"]
12
- s.date = %q{2011-03-01}
12
+ s.date = %q{2011-03-22}
13
13
  s.description = %q{Use this gem to add import/export to .csv functionality to your activerecord models}
14
14
  s.email = %q{jagdeepkh@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.homepage = %q{https://github.com/Ennova/acts_as_importable}
36
36
  s.licenses = ["MIT"]
37
37
  s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.5.3}
38
+ s.rubygems_version = %q{1.6.1}
39
39
  s.summary = %q{Makes your model importable from .csv and exportable to .csv}
40
40
 
41
41
  if s.respond_to? :specification_version then
@@ -10,9 +10,10 @@ module ModelMethods
10
10
  module ClassMethods
11
11
  # any method placed here will apply to classes
12
12
  def acts_as_importable(options = {})
13
- cattr_accessor :import_fields, :export_fields
13
+ cattr_accessor :import_fields, :export_fields, :before_import
14
14
  self.import_fields = options[:import_fields]
15
15
  self.export_fields = options[:export_fields]
16
+ self.before_import = options[:before_import]
16
17
  send :include, InstanceMethods
17
18
  end
18
19
 
@@ -25,6 +26,15 @@ module ModelMethods
25
26
  data.each_with_index do |data_row, index|
26
27
  data_row.map{|d| d.strip! if d}
27
28
 
29
+ # method to modify data_row before import
30
+ if self.before_import
31
+ if self.respond_to? self.before_import
32
+ self.send(self.before_import, data_row)
33
+ else
34
+ raise "undefined before_import method '#{self.before_import}' for #{self} class"
35
+ end
36
+ end
37
+
28
38
  begin
29
39
  class_or_association = scope_object ? scope_object.send(self.table_name) : self
30
40
  if key_field = context[:find_existing_by]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: acts_as_importable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.4
5
+ version: 0.4.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jagdeep Singh
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-01 00:00:00 +10:00
13
+ date: 2011-03-22 00:00:00 +05:30
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- hash: 985417010415812691
109
+ hash: -4426842945027895887
110
110
  segments:
111
111
  - 0
112
112
  version: "0"
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  requirements: []
120
120
 
121
121
  rubyforge_project:
122
- rubygems_version: 1.5.3
122
+ rubygems_version: 1.6.1
123
123
  signing_key:
124
124
  specification_version: 3
125
125
  summary: Makes your model importable from .csv and exportable to .csv