activerecord-importer 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -15,4 +15,10 @@ Hoe.spec 'activerecord-importer' do
15
15
 
16
16
  self.licenses = ['Public Domain']
17
17
 
18
+ self.extra_deps = [
19
+ ## ['activerecord', '~> 3.2'], # NB: will include activesupport,etc.
20
+ ['activerecord-import', '~> 0.2.11']
21
+ ### ['sqlite3', '~> 1.3'] # NB: install on your own; remove dependency
22
+ ]
23
+
18
24
  end
@@ -1,7 +1,14 @@
1
1
 
2
+ # stdlibs
3
+
2
4
  require 'pp'
3
5
  require 'yaml'
4
6
 
7
+ # 3rd party gems
8
+
9
+ require 'activerecord-import' # see https://github.com/zdennis/activerecord-import
10
+
11
+ # our own code
5
12
 
6
13
  require 'activerecord/importer/version'
7
14
  require 'activerecord/importer/runner'
@@ -73,6 +73,8 @@ module ActiveRecord::Importer
73
73
  connect_new()
74
74
 
75
75
  print "adding to table >#{model_klass.name}<"
76
+
77
+ objs = []
76
78
 
77
79
  recs.each_with_index do |rec,i|
78
80
  obj = model_klass.new
@@ -80,10 +82,16 @@ module ActiveRecord::Importer
80
82
  ## nb: use setters; lets us use obj.id = 42 e.g. mass assignment ignores/protects ids
81
83
  obj.send( "#{col}=", rec[index] )
82
84
  end
83
- obj.save!
85
+ objs << obj
86
+ ## obj.save!
87
+
84
88
  print_progress(i) # keep user entertained ...o....O...
85
89
  end
86
- puts 'OK'
90
+
91
+ ## lets use batch inserts thanks to activerecord-importer gem (see https://github.com/zdennis/activerecord-import)
92
+ model_klass.import( objs )
93
+
94
+ puts 'OK'
87
95
  end # method import_table_from_ary
88
96
 
89
97
 
@@ -102,13 +110,18 @@ module ActiveRecord::Importer
102
110
 
103
111
  print "adding records to table >#{model_klass.name}<"
104
112
 
113
+ objs = []
114
+
105
115
  recs.each_with_index do |rec,i|
106
116
  #debug_dump_record( rec )
107
- model_klass.create!( downcase_hash( rec ) )
117
+ objs << model_klass.new( downcase_hash( rec ) )
108
118
 
109
119
  print_progress(i) # keep user entertained ...o....O...
110
120
  end
111
121
 
122
+ ## lets use batch inserts thanks to activerecord-importer gem (see https://github.com/zdennis/activerecord-import)
123
+ model_klass.import( objs )
124
+
112
125
  puts 'OK'
113
126
  end
114
127
 
@@ -2,5 +2,6 @@
2
2
  module ActiveRecord ; end # forward reference
3
3
 
4
4
  module ActiveRecord::Importer
5
- VERSION = '0.3.0'
5
+ VERSION = '0.3.1'
6
6
  end
7
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-importer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerald Bauer
@@ -15,12 +15,28 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-04 00:00:00 Z
18
+ date: 2012-12-05 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rdoc
21
+ name: activerecord-import
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 1
29
+ segments:
30
+ - 0
31
+ - 2
32
+ - 11
33
+ version: 0.2.11
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdoc
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
24
40
  none: false
25
41
  requirements:
26
42
  - - ~>
@@ -31,11 +47,11 @@ dependencies:
31
47
  - 10
32
48
  version: "3.10"
33
49
  type: :development
34
- version_requirements: *id001
50
+ version_requirements: *id002
35
51
  - !ruby/object:Gem::Dependency
36
52
  name: hoe
37
53
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
54
+ requirement: &id003 !ruby/object:Gem::Requirement
39
55
  none: false
40
56
  requirements:
41
57
  - - ~>
@@ -46,7 +62,7 @@ dependencies:
46
62
  - 3
47
63
  version: "3.3"
48
64
  type: :development
49
- version_requirements: *id002
65
+ version_requirements: *id003
50
66
  description: activerecord-importer - Another Data Importer
51
67
  email: example@googlegroups.com
52
68
  executables: []