active_record_patch_first_or_create 0.0.3 → 0.0.4

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: 687f5df918527074b473e499d256c45465ed6de7
4
- data.tar.gz: 7032d1cca89085b327646e9bea2179019cf2e7c2
3
+ metadata.gz: c4c3527b478c90a4703461e25825ec2c791915ee
4
+ data.tar.gz: 18c3d931f8d3488462230f4b362e20dcfda45f06
5
5
  SHA512:
6
- metadata.gz: 694828369e70de83c036a24a747ce1556195195bb689808cad8b03222b42b6e723c481629f4d8e3559c672b27d4abcc565da060ea1c12edf5baaf5819c257589
7
- data.tar.gz: 7cde0fb1e3bb79b656612f5d818f40d4f5821de2c761db960a105380ee1ff24b818935771fef4f85a3fe8e70f6a09a357e9a08dcd5c7b1b03c817a54d794697b
6
+ metadata.gz: cd7c194effb1086fae26b403052a3aa68687204cd7307c82b5b908fda6ecd945ff9159e6b4a8d7185feb7d78b98ca14f038d41d8481b18f2e0f055d585c8a08f
7
+ data.tar.gz: d2082aa45475d5b30a535dac09aae845b6a9c65f6696cbe369be4de0e57d7fea8a3f1e4338ac1e1c9ecb81efce03902f86cf0bc8aa59a31aa61c3e909e747daa
@@ -4,6 +4,7 @@ module ActiveRecordPatchFirstOrCreate
4
4
  def self.first_or_create relation, attributes
5
5
  attributes = attributes.merge(relation.where_values_hash)
6
6
  attributes = attributes.merge(rails_timestamps(relation))
7
+ attributes = serialize_columns(relation, attributes)
7
8
 
8
9
  sql = "INSERT INTO #{relation.table_name} (#{attributes.keys.join(",")})
9
10
  SELECT #{(['?'] * attributes.values.count).join(', ')}
@@ -18,6 +19,14 @@ module ActiveRecordPatchFirstOrCreate
18
19
  time = Time.now
19
20
  { created_at: time, updated_at: time }.keep_if { |key| relation.klass.column_names.include?(key.to_s) }
20
21
  end
22
+
23
+ def self.serialize_columns relation, attributes
24
+ Hash[attributes.map do |key, value|
25
+ serializer = relation.klass.serialized_attributes[key.to_s]
26
+ value = serializer.dump(value) unless serializer.nil?
27
+ [key, value]
28
+ end]
29
+ end
21
30
  end
22
31
 
23
32
  module ActiveRecord
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordPatchFirstOrCreate
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - NDrive DevOps Team