lite-validators 1.7.0 → 1.7.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
2
  SHA256:
3
- metadata.gz: c30c0e86b00cc4525b0878c22cf5d5dfae82ffa4b3301726197d51c46efaba7e
4
- data.tar.gz: 926913306e4b90b172db620412c5018090888b0bc8f76f3c3097f583c941f705
3
+ metadata.gz: 0cbc212144b10828145cc04c3117cd994c6b5b5ffd6539b8e9cb08d45e05b15b
4
+ data.tar.gz: 31deca154872899b7faa80838416c68c1830d97982c948301dc373238bc1a3b1
5
5
  SHA512:
6
- metadata.gz: c53420f1612dd642452e7b9e1720e89cab49de4dd75d61e4c040eecc8474066908449be8d9740f39386ae52f3652428e4a6ab19c2be01b97789ba86282b242d4
7
- data.tar.gz: 6ccb77637a747d155539cd2b7fc06a868fb4e816ccf501099b891968f132bb0f6aa0d8d967aaefcf1fe33e35303464724ad0b9973cea2bd96273f50c0805d66b
6
+ metadata.gz: da30d06d89209f263bd559b008db96618947228c0a4ca358df3301fdbcc09adcfe04e6e2b0b07d426ca15cff22baf8e804deefc21e80e08b94372d2bee912535
7
+ data.tar.gz: a6219df0e0563e79ded1216f7b81794bbf02f85aa4c68fa69b395b0a31a9a2286a3d35076dc9a1aadd67955f6badf63b76dd06f69b4437d633f92183d583d646
data/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.7.1] - 2022-03-17
10
+ ### Changed
11
+ - Added polymorphic support to reference validator
12
+
9
13
  ## [1.7.0] - 2022-03-17
10
14
  ### Added
11
15
  - Added Reference validator
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-validators (1.7.0)
4
+ lite-validators (1.7.1)
5
5
  activemodel
6
6
 
7
7
  GEM
data/docs/REFERENCE.md CHANGED
@@ -12,6 +12,7 @@
12
12
  Option | Type | Available | Default
13
13
  --- | --- | --- | ---
14
14
  association | symbol | object method | attribute without `_id`
15
+ polymorphic | symbol | true, false | false
15
16
 
16
17
  #### Usage
17
18
 
@@ -19,6 +20,7 @@ association | symbol | object method | attribute without `_id`
19
20
  class User < ActiveRecord::Base
20
21
 
21
22
  validates :input_id, reference: true
23
+ validates :output_id, reference: { polymorphic: true }
22
24
  validates :output_id, reference: { association: :input }
23
25
 
24
26
  end
@@ -7,7 +7,7 @@ class ReferenceValidator < BaseValidator
7
7
  private
8
8
 
9
9
  def valid?
10
- valid_id? || valid_object?
10
+ (valid_id? && valid_type?) || valid_object?
11
11
  end
12
12
 
13
13
  def valid_id?
@@ -22,7 +22,16 @@ class ReferenceValidator < BaseValidator
22
22
 
23
23
  def valid_object?
24
24
  association_object = options[:association] || attribute.to_s.chomp('_id')
25
- record.send(association_object).present?
25
+ return true if record.send(association_object).present?
26
+
27
+ record.errors.add(association_object, *error_message)
28
+ end
29
+
30
+ def valid_type?
31
+ return true unless options[:polymorphic]
32
+
33
+ association_type = "#{attribute.to_s.chomp('_id')}_type"
34
+ record.send(association_type).present?
26
35
  end
27
36
 
28
37
  end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Validators
5
5
 
6
- VERSION = '1.7.0'
6
+ VERSION = '1.7.1'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez