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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 948bf4e57da73b4b9a35b1b76be4b296c9f717b5
4
- data.tar.gz: 0f00ace91325ea71362ed54bbe2345c7f5c73ff0
3
+ metadata.gz: 44177233d63e38c158e657fa371f0d76580a8b8d
4
+ data.tar.gz: c70e9cb4b081e3f62da40b34d28efb0828165d2a
5
5
  SHA512:
6
- metadata.gz: 443bf67a090b842cc54b3565a0715a3971e73df18aa29d85349411212687af9b47a57ce9b89d9e92ef2749950fc55fcf23a9d0ec1b84a590c782004004690ba9
7
- data.tar.gz: 7dcab4aab73e3ca734238ea49231ae7bc0b084a844a8a58c4269222bf924555690c6d1b1ca3ff23570c9783b942c4cb681800394cce36dd8b90fc6f622cdd7ef
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(&block).tap { |t| t.update!(options) }
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
@@ -1,3 +1,3 @@
1
1
  module DinoUtils
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
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.8
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-22 00:00:00.000000000 Z
11
+ date: 2016-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler