activerecord-insert_many 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d0c2ccf7d63fcc33b29d10baef77d505884c4f1
4
- data.tar.gz: 29fd5e5ed70369751e34fee477240a61d6304041
3
+ metadata.gz: 9222fd773f9ee759b910f2edfda04fde4ea3802b
4
+ data.tar.gz: a317d1422da83df65b18063628ee6905ff005bdc
5
5
  SHA512:
6
- metadata.gz: b1872faa00486c75f45abe95407ba6433369e1232d7ffcf3cbd13293b787c5b5eb1c992f75b58888fd5c2aedff4fcaf3ab5031eb73a57c3a8ba69df4c2fe424d
7
- data.tar.gz: 5faf2a908e26ebf9ab410db7a1e11c2f24d46793d41cfe657ff1210b1a19389eb4c53d4c697b56aad982e4545397edd756624252f80648a2ac36a952a9e26dee
6
+ metadata.gz: f5fb0d324f4cea1332e10bf161773e50f0ec1fc7ae020dba4a7db90834912850c3f6d2f9b7414eda62b39325866380a0aa23749cbb55304f6eb2b341b101e7d1
7
+ data.tar.gz: 75e48eed96ce5823ee9e2e7dd71c50379d5a9c48bd96be0781752f965f45970290f48bdf82219480517fa46eeaf387d947a5f919fc3cf8d398a99fdfff0f4d24
@@ -2,37 +2,40 @@ require "activerecord/insert_many/version"
2
2
  require "active_record"
3
3
  require "active_record/connection_adapters/abstract_adapter"
4
4
 
5
- module InsertMany
6
- def insert_many(fixtures)
7
- connection.insert_many(fixtures, table_name)
5
+ module ActiveRecord
6
+ module InsertMany
7
+ def insert_many(fixtures)
8
+ connection.insert_many(fixtures, table_name)
9
+ end
8
10
  end
9
- end
10
11
 
11
- module InsertManyStatement
12
- def insert_many(fixtures, table_name=self.table_name)
13
- return if fixtures.empty?
12
+ module InsertManyStatement
13
+ def insert_many(fixtures, table_name=self.table_name)
14
+ return if fixtures.empty?
14
15
 
15
- columns = schema_cache.columns_hash(table_name)
16
+ columns = schema_cache.columns_hash(table_name)
16
17
 
17
- sample = fixtures.first
18
- key_list = sample.map { |name, value| quote_column_name(name) }
18
+ sample = fixtures.first
19
+ key_list = sample.map { |name, value| quote_column_name(name) }
19
20
 
20
- value_lists = fixtures.map do |fixture|
21
- fixture.map do |name, value|
22
- quote(value, columns[name])
21
+ value_lists = fixtures.map do |fixture|
22
+ fixture.map do |name, value|
23
+ quote(value, columns[name])
24
+ end
23
25
  end
24
- end
25
26
 
26
- primary_key_column = schema_cache.primary_keys(table_name)
27
- returning = supports_returning? && primary_key_column.present? ? " RETURNING #{primary_key_column}" : ""
27
+ primary_key_column = schema_cache.primary_keys(table_name)
28
+ returning = supports_returning? && primary_key_column.present? ? " RETURNING #{primary_key_column}" : ""
28
29
 
29
- execute "INSERT INTO #{quote_table_name(table_name)} (#{key_list.join(', ')}) VALUES #{value_lists.map { |value| "(#{value.join(', ')})" }.join(",")}#{returning}", "Fixture Insert"
30
- end
30
+ execute "INSERT INTO #{quote_table_name(table_name)} (#{key_list.join(', ')}) VALUES #{value_lists.map { |value| "(#{value.join(', ')})" }.join(",")}#{returning}", "Fixture Insert"
31
+ end
31
32
 
32
- def supports_returning?
33
- true
33
+ def supports_returning?
34
+ self.class.name == "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter"
35
+ end
34
36
  end
37
+
35
38
  end
36
39
 
37
- ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, InsertManyStatement
38
- ActiveRecord::Base.extend InsertMany
40
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, ActiveRecord::InsertManyStatement
41
+ ActiveRecord::Base.extend ActiveRecord::InsertMany
@@ -1,5 +1,5 @@
1
1
  module Activerecord
2
2
  module InsertMany
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-insert_many
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Booth