tp_record_optimistic 0.0.5 → 0.1.0

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: cfc8c825a6f8da222610ac03d9029e93c4472166
4
- data.tar.gz: 7ecb57f2201986294de5111017d6c700222893fb
3
+ metadata.gz: 2651fb66b105f0ce911a99fa4d55c2fe558d3955
4
+ data.tar.gz: c31933d9f9d104fddc5653299ff1261a35542b75
5
5
  SHA512:
6
- metadata.gz: fce95f8ba825b9f79240751607035b2b1adbca255d5872fdf9e2947a9917ca34c51833a3f39f6eab9726c94e5b143282036665cb398fa495e0293746ab292bf5
7
- data.tar.gz: 929f258f7f9b39e055835ef95b3edb88146b402a7748e0e7f8a20cf01b71c838d91a4d2af56fd355ffb9450b331c9ea1e9c567d17071af529956abb8c0f2ab71
6
+ metadata.gz: ff8a74c73a85a246848b9872c91aae1bb03e0801ded4883c708981feb9edeff0821a8271135fb44b6f3624cfd6079a45bc11f6f449e080bccc62684a8e46c51b
7
+ data.tar.gz: 7d757fbd311277e9c83b0c21f73eae4c4b5fc3d42b79ebb4897f2c3b9ecfc7aff22edba42814b6e2cdd96243960034b7c3698b33e4c30f9d9456d775d60abbcb
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module TPRecordOptimistic
3
- VERSION = '0.0.5'
3
+ VERSION = '0.1.0'
4
4
  end
@@ -1,25 +1,42 @@
1
1
  # frozen_string_literal: true
2
+ require 'active_record' unless defined? ActiveRecord
3
+ # require 'active_model' unless defined? ActiveModel
2
4
 
3
5
  module TPRecordOptimistic
4
- require 'tp_record_optimistic/engine' if defined?(Rails)
5
6
  extend ActiveSupport::Concern
6
7
 
7
- # def save(*args)
8
- # super(*args)
9
- # end
10
-
11
- # alias old_save save
12
-
13
8
  def save(*args)
14
9
  super(*args)
10
+ end
11
+
12
+ alias old_save save
13
+
14
+ def save_optimistic(*args)
15
+ old_save(*args)
15
16
  rescue ActiveRecord::RecordNotUnique => e
16
17
  errors.add('all', e.to_s)
17
18
  return false
18
19
  end
19
20
 
20
- # alias save save_optimistic
21
+ # def optimistic_unique
22
+ # alias_method :save, :save_optimistic
23
+ # end
24
+ end
21
25
 
22
- def optimistic_unique; end
26
+ ActiveSupport.on_load(:active_record) do
27
+ class ActiveRecord::Base
28
+ def self.acts_as_unique
29
+ include TPRecordOptimistic
30
+ alias_method :save, :save_optimistic
31
+ end
32
+ end
23
33
  end
24
34
 
25
- ActiveRecord::Base.send(:include, TPRecordOptimistic)
35
+ # class UniqueOptimistic < ActiveModel::Validator
36
+ # def validate(record)
37
+ # record.class_eval do
38
+ # include TPRecordOptimistic
39
+ # record.send(:optimistic_unique)
40
+ # end
41
+ # end
42
+ # end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tp_record_optimistic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabricio Oliveira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails