worsemodel 0.1.8 → 0.1.9
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/supermodel/random_id.rb +4 -2
- data/lib/supermodel/validations/uniqueness.rb +4 -9
- data/lib/supermodel/validations.rb +4 -4
- data/supermodel.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ce7f3751966028db5b242d65a3c15f81fc3e21d
|
4
|
+
data.tar.gz: 747684787f00a309f9ffbd7de06afc2ff038c147
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fb68b5801d1a246f064deb4f4dc3c522fb9b2890c41637de62b394c3a5e5d1e40870b3a849e71620279314bd4e396c752c1a59e2f48f71758d9766616a85796
|
7
|
+
data.tar.gz: 630967abac0d6b6a5d6a890e2693e2c43f28a89ce4614bf3a525b522d5aa94a0f1018ccebd509a0cc04f69962f5977c1e83e5afd2346dee7547a64d498ad855d
|
data/lib/supermodel/random_id.rb
CHANGED
@@ -1,16 +1,11 @@
|
|
1
1
|
module SuperModel
|
2
2
|
module Validations
|
3
3
|
class UniquenessValidator < ActiveModel::EachValidator
|
4
|
-
|
5
|
-
|
4
|
+
|
6
5
|
def validate_each(record, attribute, value)
|
7
|
-
alternate =
|
6
|
+
alternate = record.class.find_by_attribute(attribute, value)
|
8
7
|
return unless alternate
|
9
|
-
record.errors.add(attribute,
|
10
|
-
end
|
11
|
-
|
12
|
-
def setup(klass)
|
13
|
-
@klass = klass
|
8
|
+
record.errors.add(attribute, 'must be unique', default: options[:message])
|
14
9
|
end
|
15
10
|
end
|
16
11
|
|
@@ -37,4 +32,4 @@ module SuperModel
|
|
37
32
|
end
|
38
33
|
end
|
39
34
|
end
|
40
|
-
end
|
35
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'supermodel/validations/uniqueness'
|
2
|
+
|
1
3
|
module SuperModel
|
2
4
|
module Validations
|
3
5
|
extend ActiveSupport::Concern
|
@@ -6,7 +8,7 @@ module SuperModel
|
|
6
8
|
included do
|
7
9
|
alias_method_chain :save, :validation
|
8
10
|
end
|
9
|
-
|
11
|
+
|
10
12
|
def save_with_validation(options = nil)
|
11
13
|
perform_validation = case options
|
12
14
|
when Hash
|
@@ -16,7 +18,7 @@ module SuperModel
|
|
16
18
|
else
|
17
19
|
options
|
18
20
|
end
|
19
|
-
|
21
|
+
|
20
22
|
if perform_validation && valid? || !perform_validation
|
21
23
|
save_without_validation
|
22
24
|
true
|
@@ -28,5 +30,3 @@ module SuperModel
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
31
|
-
|
32
|
-
require "supermodel/validations/uniqueness"
|
data/supermodel.gemspec
CHANGED