active_record_patch_first_or_create 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44c5f873bc5ceb106f575bdb7c98958aec1ae998
4
- data.tar.gz: 09f5165e294d8898ce2addd48f3e10765151d0c4
3
+ metadata.gz: 687f5df918527074b473e499d256c45465ed6de7
4
+ data.tar.gz: 7032d1cca89085b327646e9bea2179019cf2e7c2
5
5
  SHA512:
6
- metadata.gz: 8fb545d0c0195854e26417bbbbecbe864e85a286f420a3e319931f11e1aad279ccfe76ba4ca4d552718d7f1235fc04ddfb57fa382fea956d41d484148d0ece94
7
- data.tar.gz: d84a7da4a0776a9edfc38723d19455a3e0650f0593ca96261c868379304ed7bd56c29bd93fd1176ca7268f0d14573c1b286fd538a821ca0da96dbd55c67b3995
6
+ metadata.gz: 694828369e70de83c036a24a747ce1556195195bb689808cad8b03222b42b6e723c481629f4d8e3559c672b27d4abcc565da060ea1c12edf5baaf5819c257589
7
+ data.tar.gz: 7cde0fb1e3bb79b656612f5d818f40d4f5821de2c761db960a105380ee1ff24b818935771fef4f85a3fe8e70f6a09a357e9a08dcd5c7b1b03c817a54d794697b
@@ -3,7 +3,7 @@ require "active_record_patch_first_or_create/version"
3
3
  module ActiveRecordPatchFirstOrCreate
4
4
  def self.first_or_create relation, attributes
5
5
  attributes = attributes.merge(relation.where_values_hash)
6
- attributes = attributes.merge(rails_timestamps) if relation.klass.record_timestamps?
6
+ attributes = attributes.merge(rails_timestamps(relation))
7
7
 
8
8
  sql = "INSERT INTO #{relation.table_name} (#{attributes.keys.join(",")})
9
9
  SELECT #{(['?'] * attributes.values.count).join(', ')}
@@ -14,9 +14,9 @@ module ActiveRecordPatchFirstOrCreate
14
14
  relation.first
15
15
  end
16
16
 
17
- def self.rails_timestamps
17
+ def self.rails_timestamps relation
18
18
  time = Time.now
19
- { created_at: time, updated_at: time }
19
+ { created_at: time, updated_at: time }.keep_if { |key| relation.klass.column_names.include?(key.to_s) }
20
20
  end
21
21
  end
22
22
 
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordPatchFirstOrCreate
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_patch_first_or_create
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - NDrive DevOps Team
@@ -46,7 +46,6 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - ".gitignore"
50
49
  - Gemfile
51
50
  - LICENSE.txt
52
51
  - README.md
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp