activerecord_eternal_validator 0.1.0 → 0.1.1
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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 168a9c4309860ec50c882c92f71ebffca0838bb0
|
4
|
+
data.tar.gz: 8bffe2870e274abacb797dfc1ce44c1d10552f1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5de5f260eb0bae7771d78ae15d2da99457979e22540cc356a89a3c2bc6adea14701741041bd76191deb32813ea28823915b46f378cccb73950e539789eefaa01
|
7
|
+
data.tar.gz: 8fdcdc57dd34a7cb308949234f224c39e5fd0e76bd24444d0e1ad627d4b2c8875244ea0a7376ad4f78f21a681c11a0ea911695408c118daa499da2e94f5723c9
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# ActiverecordEternalValidator
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
It's a activerecord validator, which validates that value is not changed.
|
4
|
+
It validates value only on update.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -22,7 +21,17 @@ Or install it yourself as:
|
|
22
21
|
|
23
22
|
## Usage
|
24
23
|
|
25
|
-
|
24
|
+
```
|
25
|
+
class Person < ActiveRecord::Base
|
26
|
+
validates :birthday, 'activerecord_eternal_validator/eternal': true
|
27
|
+
end
|
28
|
+
|
29
|
+
person = Person.create!(birthday: Date.new(1994, 7, 7))
|
30
|
+
|
31
|
+
person.birthday = Date.today
|
32
|
+
puts person.valid?
|
33
|
+
#=> false
|
34
|
+
```
|
26
35
|
|
27
36
|
## Development
|
28
37
|
|
@@ -2,12 +2,16 @@
|
|
2
2
|
|
3
3
|
module ActiverecordEternalValidator
|
4
4
|
class EternalValidator < ::ActiveModel::EachValidator
|
5
|
-
def initialize(
|
6
|
-
|
5
|
+
def initialize(options)
|
6
|
+
options.merge!(on: :update)
|
7
7
|
super
|
8
8
|
end
|
9
9
|
|
10
10
|
def validate_each(record, attribute, value)
|
11
|
+
if record.attribute_changed?(attribute) && options[:change_from_nil] && record.attribute_was(attribute).nil?
|
12
|
+
return
|
13
|
+
end
|
14
|
+
|
11
15
|
if record.send("#{attribute}_changed?")
|
12
16
|
record.errors.add(attribute, 'cannot be changed.')
|
13
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord_eternal_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nishisuke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.5.2.1
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: ActiveRecord validator, which prevent change column on update
|