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 +4 -4
- data/lib/tp_record_optimistic/version.rb +1 -1
- data/lib/tp_record_optimistic.rb +27 -10
- 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: 2651fb66b105f0ce911a99fa4d55c2fe558d3955
|
4
|
+
data.tar.gz: c31933d9f9d104fddc5653299ff1261a35542b75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff8a74c73a85a246848b9872c91aae1bb03e0801ded4883c708981feb9edeff0821a8271135fb44b6f3624cfd6079a45bc11f6f449e080bccc62684a8e46c51b
|
7
|
+
data.tar.gz: 7d757fbd311277e9c83b0c21f73eae4c4b5fc3d42b79ebb4897f2c3b9ecfc7aff22edba42814b6e2cdd96243960034b7c3698b33e4c30f9d9456d775d60abbcb
|
data/lib/tp_record_optimistic.rb
CHANGED
@@ -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
|
-
#
|
21
|
+
# def optimistic_unique
|
22
|
+
# alias_method :save, :save_optimistic
|
23
|
+
# end
|
24
|
+
end
|
21
25
|
|
22
|
-
|
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
|
-
|
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
|
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-
|
11
|
+
date: 2017-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|