validate_specific_value 0.2.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3c96f327f719b1d16c259294c19ef5db4ebee2f5f3fd2a539e35a4077350032
4
- data.tar.gz: f9a9743e778a4e0392fa1fe18134984d324a9662f0fc39aa9fb579cb9cc110c0
3
+ metadata.gz: eba2b32a298365358878cd5e38acc5dca357f3f5165de150fe2a49ce0a1c3eb8
4
+ data.tar.gz: f776085436cc19d14ab160f7dee169dc0f0b4671d8c11fdf0d563b76e9ced752
5
5
  SHA512:
6
- metadata.gz: e8a7b03ba09e1ed9ed1842c34d37bba57f99cdb0340d84f4bfa75848a5a005c52a5d6ea01fcfd4c2bf3d08eaadfc4c11d099a1c74a62d099e427e4a69d10f44d
7
- data.tar.gz: 2b02d6d984a7ceab27e633b358b7fb7ff0119cc75a79e8344c5f2665e44bbbc0b6a64a95d2e2b91369a18bd636f065a21790486689d26d93807d7652ad5c8da4
6
+ metadata.gz: 991303fda26deab88ac2483ff9186f15955dbb1006fb1094685d6487b99170c0981d9f127e1933b9b3c121a2a80d2a19ff5e71fc395c5332d2ae2c13036a7988
7
+ data.tar.gz: 7ba5f676dbb4fecd7510e1b40c44a3a1da6536cd9625d00f1ab5d2c7598b028ebe00752a56c62248e6a0d32d08c42547d0808e7dc1138d7ae781e6f4d7b79ee3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validate_specific_value (0.2.1)
4
+ validate_specific_value (0.3.0)
5
5
  activerecord (>= 4.2, < 6.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -26,9 +26,7 @@ class User < ApplicationRecord
26
26
  end
27
27
  ```
28
28
 
29
- The first value will be the initial value. This gives you:
30
-
31
- #### Accessor Methods
29
+ ## Accessor Methods
32
30
 
33
31
  Instance context:
34
32
 
@@ -49,6 +47,22 @@ User.valid_name?('duplicate_name')
49
47
  # => false
50
48
  ```
51
49
 
50
+ ## Implementation
51
+
52
+ The implementation is quite simple.
53
+
54
+ ```ruby
55
+ class User < ApplicationRecord
56
+ def valid_name?
57
+ errors.clear
58
+ self.class.validators_on(:name).each do |validator|
59
+ validator.validate_each(self, :name, self[:name])
60
+ end
61
+ errors.empty?
62
+ end
63
+ end
64
+ ```
65
+
52
66
  ## Contributing
53
67
 
54
68
  Everyone is encouraged to help improve this project. Here are a few ways you can help:
@@ -5,12 +5,11 @@ module ValidateSpecificValue
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  class_methods do
8
- # def valid_[attribute]? ... end
9
- # def self.valid_[attribute]?(value) ... end
10
8
  def validates_specific(column)
11
9
  column = column.to_sym
12
10
  method_name = "valid_#{column}?"
13
11
 
12
+ # def valid_[attribute]? ... end
14
13
  unless method_defined?(method_name)
15
14
  define_method method_name do
16
15
  errors.clear
@@ -21,11 +20,10 @@ module ValidateSpecificValue
21
20
  end
22
21
  end
23
22
 
23
+ # def self.valid_[attribute]?(value) ... end
24
24
  define_singleton_method method_name do |value, errors = {}|
25
- instance = self.new
26
- validators_on(column).each do |validator|
27
- validator.validate_each(instance, column, value)
28
- end
25
+ instance = self.new(column => value)
26
+ instance.send(method_name)
29
27
  errors[column] = instance.errors[column]
30
28
  errors[column].empty?
31
29
  end
@@ -1,3 +1,3 @@
1
1
  module ValidateSpecificValue
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validate_specific_value
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ts-3156
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-19 00:00:00.000000000 Z
11
+ date: 2018-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord