activerecord_eternal_validator 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 3fafb6640927b5a37bf5d5e5b9331119c35699a2d5b66b270e7630db21545390
4
- data.tar.gz: 53265043cba19c98111f867b7d5c10243786d09f6d270deb3208aeef077a9ae8
2
+ SHA1:
3
+ metadata.gz: 168a9c4309860ec50c882c92f71ebffca0838bb0
4
+ data.tar.gz: 8bffe2870e274abacb797dfc1ce44c1d10552f1f
5
5
  SHA512:
6
- metadata.gz: 2e3dad3ac1bad19bae2308fb783c47750dc860bb25c74b879237396d70c4737a11596699a25b01efb77d10732aea56a6128adb91685ad588f00a5465dbf0d12b
7
- data.tar.gz: f9f90edb4046e9c329da122c1b39bcc5469bbb74cec638727adcd8a32698d0207e660a0717b732bc0c2e2f2e34f3376a321238018dca066c5c4ac85163d4dc42
6
+ metadata.gz: 5de5f260eb0bae7771d78ae15d2da99457979e22540cc356a89a3c2bc6adea14701741041bd76191deb32813ea28823915b46f378cccb73950e539789eefaa01
7
+ data.tar.gz: 8fdcdc57dd34a7cb308949234f224c39e5fd0e76bd24444d0e1ad627d4b2c8875244ea0a7376ad4f78f21a681c11a0ea911695408c118daa499da2e94f5723c9
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # ActiverecordEternalValidator
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/activerecord_eternal_validator`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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(option)
6
- option.merge!(on: :update)
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
@@ -1,3 +1,3 @@
1
1
  module ActiverecordEternalValidator
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'
3
3
  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.0
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-06-26 00:00:00.000000000 Z
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.7.6
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