vanilla_validator 0.4.1 → 0.4.3

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: 18fca42643c60e0140faa262a60f656048351aa0375c8107d044192ebfae9b3c
4
- data.tar.gz: 343965cb3a3ece303171a48e8a9133003388f0db7cc49a57b42e72720e236ad1
3
+ metadata.gz: 4324331073afc365ec394629ec05e57c18e903f4c6fc3e5ad7616bc65a580ccf
4
+ data.tar.gz: '0292b7641af17e54a980051d6719dbf2230434035e364ea54d2a909da21b6ee9'
5
5
  SHA512:
6
- metadata.gz: 7cde9b8798c746be0b94433a5d5ad4cf722b2d222f102eb71d277d6b7debd72fa3dc3449de2fb3200ac4206d17256a3a0c2986af4a39082b7f7331685e81ed1e
7
- data.tar.gz: 3becd2a2e661095532dcf6039a02e8c2e6f5498b46647db9de956f04e8b726f57d70a710f42e082ba8800a9cac0d5209ab868115b56ab786ef155a683769dec5
6
+ metadata.gz: a77727a1da0477cbf349b638ac523489fb5d4dacf34765d142d07a521112ffc384084d0310af1cca77521148745bcca9998db3733ad4d29d86ead58351819d2b
7
+ data.tar.gz: 6bddecd7792bc7b44f85ef01a3cc00c696d6a6952226cd5b309c05a1e443597aaa1b1c7042d28415d897a026b2aabfc04dac32ea9df63c3357e0dfa233ec32d8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vanilla_validator (0.1.4)
4
+ vanilla_validator (0.4.2)
5
5
  activesupport
6
6
  i18n
7
7
  zeitwerk (~> 2.5)
@@ -49,9 +49,11 @@ GEM
49
49
  loofah (2.21.4)
50
50
  crass (~> 1.0.2)
51
51
  nokogiri (>= 1.12.0)
52
+ mini_portile2 (2.8.5)
52
53
  minitest (5.20.0)
53
54
  mutex_m (0.1.2)
54
- nokogiri (1.15.4-x86_64-linux)
55
+ nokogiri (1.15.4)
56
+ mini_portile2 (~> 2.8.2)
55
57
  racc (~> 1.4)
56
58
  racc (1.7.3)
57
59
  rack (3.0.8)
@@ -85,6 +87,7 @@ GEM
85
87
  zeitwerk (2.6.12)
86
88
 
87
89
  PLATFORMS
90
+ arm64-darwin-22
88
91
  x86_64-linux
89
92
 
90
93
  DEPENDENCIES
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## 🚧 Project Under Development 🚧
2
2
 
3
+ [![Ruby Gem](https://github.com/leurias/vanilla_validator/actions/workflows/gem-push.yml/badge.svg?branch=main)](https://github.com/leurias/vanilla_validator/actions/workflows/gem-push.yml)
4
+
3
5
  ## VanillaValidator
4
6
 
5
7
  VanillaValidator is a lightweight and clean solution for implementing validation in Ruby. It inspired from Laravel Validator and allows you to separate validations from the model layer in your Rails applications. With this gem, you can easily define and enforce validation rules for input data, ensuring the consistency and cleanliness of your application's data.
@@ -4,8 +4,8 @@ module VanillaValidator
4
4
  attr_accessor :validated, :errors
5
5
 
6
6
  def initialize(validated, errors = {})
7
- @validated = validated
8
- @errors = errors
7
+ @validated = validated.with_indifferent_access
8
+ @errors = errors.with_indifferent_access
9
9
  end
10
10
 
11
11
  def valid?
@@ -14,8 +14,8 @@ module VanillaValidator
14
14
  #
15
15
  # Returns: The extracted data, or nil if the path does not lead to a valid value.
16
16
  #
17
- def self.get(data, path)
18
- splited_path = path.to_s.split('.')
17
+ def self.get(data, path)
18
+ splited_path = path.split('.')
19
19
 
20
20
  raise "Too many path segments (maximum allowed is 5)" if splited_path.length > 5
21
21
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VanillaValidator
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.3"
5
5
  end
@@ -4,6 +4,7 @@ require 'i18n'
4
4
  require 'uri'
5
5
  require 'date'
6
6
  require 'active_support/inflector'
7
+ require "active_support/core_ext/hash/indifferent_access"
7
8
  require "zeitwerk"
8
9
 
9
10
  # Configure Zeitwerk to load the classes and modules.
@@ -31,6 +32,7 @@ module VanillaValidator
31
32
  #
32
33
  # Returns a Result object containing the validated attributes and any errors.
33
34
  def validate(input, contract, options = {})
35
+ input = input.with_indifferent_access
34
36
  @raw_input = input.dup
35
37
 
36
38
  errors = {}
@@ -38,6 +40,8 @@ module VanillaValidator
38
40
  stop_on_first_failure = options[:stop_on_first_failure]
39
41
 
40
42
  contract.each do |attribute, term|
43
+ attribute = attribute.to_s
44
+
41
45
  value = ValueExtractor.get(input, attribute)
42
46
  rules = RuleParser.parse(term)
43
47
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanilla_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Farid Mohammadi