Empact-activerecord-import 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.3
@@ -5,10 +5,12 @@ module ActiveRecord::Import::MysqlAdapter
5
5
  # Returns the maximum number of bytes that the server will allow
6
6
  # in a single packet
7
7
  def max_allowed_packet # :nodoc:
8
- result = execute( "SHOW VARIABLES like 'max_allowed_packet';" )
9
- # original Mysql gem responds to #fetch_row while Mysql2 responds to #first
10
- val = result.respond_to?(:fetch_row) ? result.fetch_row[1] : result.first[1]
11
- val.to_i
8
+ @max_allowed_packet ||= begin
9
+ result = execute( "SHOW VARIABLES like 'max_allowed_packet';" )
10
+ # original Mysql gem responds to #fetch_row while Mysql2 responds to #first
11
+ val = result.respond_to?(:fetch_row) ? result.fetch_row[1] : result.first[1]
12
+ val.to_i
13
+ end
12
14
  end
13
15
 
14
16
  # Returns a generated ON DUPLICATE KEY UPDATE statement given the passed
@@ -160,8 +160,13 @@ class ActiveRecord::Base
160
160
 
161
161
  is_validating = options.delete( :validate )
162
162
 
163
+ if !args.last.is_a?( Array )
164
+ raise ArgumentError, '.import expects one or two Array arguments'
165
+ # supports empty array
166
+ elsif args.last.empty?
167
+ return ActiveRecord::Import::Result.new([], 0)
163
168
  # assume array of model objects
164
- if args.last.is_a?( Array ) and args.last.first.is_a? ActiveRecord::Base
169
+ elsif args.last.first.is_a? ActiveRecord::Base
165
170
  models = args.pop
166
171
  column_names = args.first || self.column_names.dup
167
172
 
@@ -173,19 +178,16 @@ class ActiveRecord::Base
173
178
  end
174
179
  # end
175
180
  end
176
- # supports empty array
177
- elsif args.last.is_a?( Array ) and args.last.empty?
178
- return ActiveRecord::Import::Result.new([], 0) if args.last.empty?
179
- # supports 2-element array and array
180
- elsif args.size == 2 and args.first.is_a?( Array ) and args.last.is_a?( Array )
181
+ # supports 2-element array and array
182
+ elsif args.size == 2 and args.first.is_a?( Array )
181
183
  column_names, array_of_attributes = args
184
+
185
+ # dup the passed in array so we don't modify it unintentionally
186
+ array_of_attributes = array_of_attributes.dup
182
187
  else
183
- raise ArgumentError.new( "Invalid arguments!" )
188
+ raise ArgumentError
184
189
  end
185
190
 
186
- # dup the passed in array so we don't modify it unintentionally
187
- array_of_attributes = array_of_attributes.dup
188
-
189
191
  # Force the primary key col into the insert if it's not
190
192
  # on the list and we are using a sequence and stuff a nil
191
193
  # value for it into each row so the sequencer will fire later
@@ -199,12 +201,13 @@ class ActiveRecord::Base
199
201
  add_special_rails_stamps column_names, array_of_attributes, options
200
202
  end
201
203
 
202
- return_obj = if is_validating
203
- import_with_validations( column_names, array_of_attributes, options )
204
- else
205
- num_inserts = import_without_validations_or_callbacks( column_names, array_of_attributes, options )
206
- ActiveRecord::Import::Result.new([], num_inserts)
207
- end
204
+ return_obj =
205
+ if is_validating
206
+ import_with_validations( column_names, array_of_attributes, options )
207
+ else
208
+ num_inserts = import_without_validations_or_callbacks( column_names, array_of_attributes, options )
209
+ ActiveRecord::Import::Result.new([], num_inserts)
210
+ end
208
211
 
209
212
  if options[:synchronize]
210
213
  sync_keys = options[:synchronize_keys] || [self.primary_key]
@@ -239,7 +242,7 @@ class ActiveRecord::Base
239
242
  instance = new do |model|
240
243
  hsh.each_pair{ |k,v| model.send("#{k}=", v) }
241
244
  end
242
- if not instance.valid?
245
+ if !instance.valid?
243
246
  array_of_attributes[ i ] = nil
244
247
  failed_instances << instance
245
248
  end
@@ -33,7 +33,7 @@ module ActiveRecord # :nodoc:
33
33
 
34
34
  klass = instances.first.class
35
35
 
36
- fresh_instances = klass.find( :all, :conditions=>conditions, :order=>order )
36
+ fresh_instances = klass.where(conditions).order(order).all
37
37
  instances.each do |instance|
38
38
  matched_instance = fresh_instances.detect do |fresh_instance|
39
39
  keys.all?{ |key| fresh_instance.send(key) == instance.send(key) }
@@ -42,7 +42,9 @@ module ActiveRecord # :nodoc:
42
42
  if matched_instance
43
43
  instance.clear_aggregation_cache
44
44
  instance.clear_association_cache
45
- instance.instance_variable_set '@attributes', matched_instance.attributes
45
+ instance.instance_variable_get('@attributes').update(matched_instance.instance_variable_get('@attributes'))
46
+ instance.instance_variable_set('@columns_hash', matched_instance.instance_variable_get('@columns_hash'))
47
+ instance.instance_variable_set('@attributes_cache', {})
46
48
  end
47
49
  end
48
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Empact-activerecord-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,22 +10,27 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-02 00:00:00.000000000 Z
13
+ date: 2012-05-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &70139591717760 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - ~>
20
+ - - ! '>='
21
21
  - !ruby/object:Gem::Version
22
- version: '3.0'
22
+ version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70139591717760
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 3.0.0
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: rake
28
- requirement: &70139591717020 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '0'
34
39
  type: :development
35
40
  prerelease: false
36
- version_requirements: *70139591717020
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: jeweler
39
- requirement: &70139591715840 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,7 +54,12 @@ dependencies:
44
54
  version: 1.4.0
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *70139591715840
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 1.4.0
48
63
  description: Extraction of the ActiveRecord::Base#import functionality from ar-extensions
49
64
  for Rails 3 and beyond
50
65
  email: ben.woosley@gmail.com
@@ -84,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
99
  version: '0'
85
100
  segments:
86
101
  - 0
87
- hash: -2510972536084557181
102
+ hash: -3863858438145436017
88
103
  required_rubygems_version: !ruby/object:Gem::Requirement
89
104
  none: false
90
105
  requirements:
@@ -93,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
108
  version: '0'
94
109
  requirements: []
95
110
  rubyforge_project:
96
- rubygems_version: 1.8.11
111
+ rubygems_version: 1.8.23
97
112
  signing_key:
98
113
  specification_version: 3
99
114
  summary: Bulk-loading extension for ActiveRecord