active_model_validations_reflection 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e2eb7955432907c345430ec357aed9d1ffac7166a4f3c040e1e468a76dfa8e4
4
- data.tar.gz: 411494f20616f128d5774f02973fcb2f2a6fe0c36be578d1bc1846422ecda144
3
+ metadata.gz: a2157bd5ce0dd6c8eaec27072fa186ac7bd93409ba32df041a86f5fe583cf208
4
+ data.tar.gz: e6d3f51343264ec744d0395dc090a416a13f1a5fc039caaa9e8aba1384f91816
5
5
  SHA512:
6
- metadata.gz: fd9a9e716d1099f06cf253f8583073458c9d0e37d1ebdd9debe5cc864e7acf208cca3bf7cd503935c8240a36444deee020b1a39270343bdb81b3403adf51aa6e
7
- data.tar.gz: d09024a5d8d1e35ee571da1e299d8e1d8a183834296df006d03bd9f21c4045df56a85ff26fb07b427573dbd50752210afdeeca9ce67167683cbfcd91e17164fb
6
+ metadata.gz: 8e0b853c7190f4bcda9791ba89ad92ab3fd8c8c7806c46dc2bf9e346750543af003f09e5751a40ea4b4c0e894e03947d5b47a03dcd57791981f00296e8e6a710
7
+ data.tar.gz: 7318a479b2b89410b6499ec1388a84b515b5d32deb31e83c9147bce2cfb2873dc303e8978fc0fd39955503b9dba62ef290552dc070eb59ab75d14493b09c8e22
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_model_validations_reflection (0.1.1)
4
+ active_model_validations_reflection (0.1.2)
5
5
  activemodel (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
 
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Installation
9
9
 
10
- `Rack::AddressMunging` is distributed as a gem and available on [rubygems.org](https://rubygems.org/gems/rack-address_munging) so you can add it to your `Gemfile` or install it manually with:
10
+ `ActiveModel::Validations::Reflection` is distributed as a gem and available on [rubygems.org](https://rubygems.org/gems/active_model_validations_reflection) so you can add it to your `Gemfile` or install it manually with:
11
11
 
12
12
  ```ruby
13
13
  gem install active_model_validations_reflection
@@ -61,9 +61,9 @@ Article.validators_on_of_kinds(:date, :timeliness)
61
61
  # => []
62
62
  ```
63
63
 
64
- ### `#relevant_validators_on(attribute, *kinds)`
64
+ ### `#relevant_validators(*kinds)` & `#relevant_validators_on(attribute, *kinds)`
65
65
 
66
- Returns validator that will be applied to the named attribute considering the instance current state: flat validators and conditional validators whose condition is met.
66
+ Returns validator that will be applied considering the instance current state: flat validators and conditional validators whose condition is met.
67
67
 
68
68
  ```ruby
69
69
  class Article < ApplicationRecord
@@ -77,6 +77,8 @@ class Article < ApplicationRecord
77
77
  end
78
78
 
79
79
  article = Article.new
80
+ article.relevant_validators
81
+ # => [#<ActiveModel::Validations::PresenceValidator […]>]
80
82
  article.relevant_validators_on(:date)
81
83
  # => [#<ActiveModel::Validations::PresenceValidator […]>]
82
84
 
@@ -59,6 +59,14 @@ module ActiveModel
59
59
  end
60
60
  end
61
61
 
62
+ def relevant_validators(*kinds)
63
+ self.class.validators_of_kinds(*kinds).select do |validator|
64
+ next true if Helpers.flat_validator?(validator)
65
+
66
+ Helpers.relevant_validator?(validator, self)
67
+ end
68
+ end
69
+
62
70
  def relevant_validators_on(attribute, *kinds)
63
71
  self.class.validators_on_of_kinds(attribute, *kinds).select do |validator|
64
72
  next true if Helpers.flat_validator?(validator)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveModelValidationsReflection
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_validations_reflection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaël-Ian Havard