Skip to content
This repository
Browse code

Perf: refactor method.

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
commit ea35ccfe2014aff208601b98442ff03fa76269a9 1 parent 0580f5a
Emilio Tagua authored September 22, 2010 spastorino committed September 22, 2010
19  activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -49,23 +49,20 @@ def insert_record(record, force = true, validate = true)
49 49
             timestamps = record_timestamp_columns(record)
50 50
             timezone   = record.send(:current_time_from_proper_timezone) if timestamps.any?
51 51
 
52  
-            attributes = columns.inject({}) do |attrs, column|
  52
+            attributes = Hash[columns.map do |column|
53 53
               name = column.name
54  
-              case name.to_s
  54
+              value = case name.to_s
55 55
                 when @reflection.primary_key_name.to_s
56  
-                  attrs[relation[name]] = @owner.id
  56
+                  @owner.id
57 57
                 when @reflection.association_foreign_key.to_s
58  
-                  attrs[relation[name]] = record.id
  58
+                  record.id
59 59
                 when *timestamps
60  
-                  attrs[relation[name]] = timezone
  60
+                  timezone
61 61
                 else
62  
-                  if record.has_attribute?(name)
63  
-                    value = @owner.send(:quote_value, record[name], column)
64  
-                    attrs[relation[name]] = value unless value.nil?
65  
-                  end
  62
+                  @owner.send(:quote_value, record[name], column) if record.has_attribute?(name)
66 63
               end
67  
-              attrs
68  
-            end
  64
+              [relation[name], value] unless value.nil?
  65
+            end]
69 66
 
70 67
             relation.insert(attributes)
71 68
           end

0 notes on commit ea35ccf

Please sign in to comment.
Something went wrong with that request. Please try again.