dino_utils 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dino/upsert.rb +8 -3
- data/lib/dino_utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44177233d63e38c158e657fa371f0d76580a8b8d
|
4
|
+
data.tar.gz: c70e9cb4b081e3f62da40b34d28efb0828165d2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a23e557aab8b06e68d59175c3b9852b15a85e8d9eb7ed761fc182c07c40d7f9f9cb3222b06e74f8511007051d7bafd139b625a6b51c18425bb78bb3a64558e4
|
7
|
+
data.tar.gz: 264c63e5d3efae192c95c31f2871b1f78284c33f337f8e0ac8d7f9caa386c580816fc8973e619a18e311266bc3ba5a00f07a30230cbe05e9138868eec245978f
|
data/lib/dino/upsert.rb
CHANGED
@@ -7,8 +7,8 @@ module Dino
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
# User.upsert
|
9
9
|
module ClassMethods
|
10
|
-
def upsert(*args)
|
11
|
-
Dino::Upsert.upsert(self, *args)
|
10
|
+
def upsert(*args, &block)
|
11
|
+
Dino::Upsert.upsert(self, *args, &block)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -30,7 +30,12 @@ module Dino
|
|
30
30
|
end
|
31
31
|
begin
|
32
32
|
klass.transaction(requires_new: true) do
|
33
|
-
klass.where(data_copy).first_or_initialize
|
33
|
+
object = klass.where(data_copy).first_or_initialize
|
34
|
+
block.call(object) if block
|
35
|
+
object.tap do |t|
|
36
|
+
t.assign_attributes(options)
|
37
|
+
t.save! if t.changed?
|
38
|
+
end
|
34
39
|
end
|
35
40
|
rescue PG::UniqueViolation, ActiveRecord::RecordNotUnique
|
36
41
|
# If there's a unique violation, retry this. But only a certain amount
|
data/lib/dino_utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dino_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Van Dyk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|