acts_as_importable 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/acts_as_importable.gemspec +2 -2
- data/lib/import_export.rb +8 -3
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/acts_as_importable.gemspec
CHANGED
@@ -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.
|
8
|
+
s.version = "0.3.0"
|
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-01-
|
12
|
+
s.date = %q{2011-01-13}
|
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 = [
|
data/lib/import_export.rb
CHANGED
@@ -23,11 +23,16 @@ module ModelMethods
|
|
23
23
|
ActiveRecord::Base.transaction do
|
24
24
|
data.each_with_index do |data_row, index|
|
25
25
|
data_row.map{|d| d.strip! if d}
|
26
|
-
Rails.logger.info data_row.inspect
|
27
26
|
|
28
27
|
begin
|
29
|
-
|
30
|
-
|
28
|
+
class_or_association = scope_object ? scope_object.send(self.table_name) : self
|
29
|
+
key_field = self.import_fields.first
|
30
|
+
key_value = data_row[0]
|
31
|
+
finder_method = "find_by_#{key_field}"
|
32
|
+
existing_element = class_or_association.send(finder_method, key_value)
|
33
|
+
element = existing_element || class_or_association.new
|
34
|
+
|
35
|
+
Rails.logger.info "#{element.new_record? ? "Creating new" : "Updating existing"} record from #{data_row.inspect}"
|
31
36
|
|
32
37
|
self.import_fields.each_with_index do |field_name, field_index|
|
33
38
|
if field_name.include?('.')
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_importable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jagdeep Singh
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-13 00:00:00 +05:30
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|