validates_unchangeable 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/validates_unchangeable/active_model.rb +12 -1
- data/lib/validates_unchangeable/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39fc55822ab044b146e8338575a9b8e678c9fe3c167eeb28290cde8373268c71
|
4
|
+
data.tar.gz: 4be3948be8335c367a6c370812f21b54132d4c5ce2e1de33fc57a527c042259c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 482999348c3917f6374c6b41bb8cdd5cda97e6c7e76c372488223a9e1871067a00c22553db9f17b1f0237d02144ef0b107ebddfa0f26953fb5490039010dda04
|
7
|
+
data.tar.gz: a106901c613e358ece6a8ca907506610afd3615a767e7f1c5434942cff68ef09c4ef0c6f015d30b55a136b75ee536368198623a8cec838021bbad427b03e84d6
|
data/Gemfile.lock
CHANGED
@@ -6,10 +6,21 @@ module ActiveModel
|
|
6
6
|
module Validations
|
7
7
|
class UnchangeableValidator < ActiveModel::EachValidator
|
8
8
|
def validate_each(record, attribute, _value)
|
9
|
-
|
9
|
+
if !record.public_send("#{attribute}_changed?") ||
|
10
|
+
record.public_send("#{attribute}_was") == default_value_for(record, attribute)
|
11
|
+
return
|
12
|
+
end
|
10
13
|
|
11
14
|
record.errors.add(attribute, :unchangeable)
|
12
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def default_value_for(record, attribute)
|
20
|
+
return unless record.class.respond_to?(:column_defaults)
|
21
|
+
|
22
|
+
record.class.column_defaults[attribute.to_s]
|
23
|
+
end
|
13
24
|
end
|
14
25
|
end
|
15
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_unchangeable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vital Ryabchinskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
177
|
- !ruby/object:Gem::Version
|
178
178
|
version: '0'
|
179
179
|
requirements: []
|
180
|
-
rubygems_version: 3.
|
180
|
+
rubygems_version: 3.2.3
|
181
181
|
signing_key:
|
182
182
|
specification_version: 4
|
183
183
|
summary: Library for validating unchangeable attributes.
|