hanami-validations 2.2.0.beta1 → 2.2.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/hanami-validations.gemspec +0 -1
- data/lib/hanami/validations/version.rb +1 -1
- data/lib/hanami/validations.rb +0 -96
- metadata +3 -19
- data/lib/hanami/validations/form.rb +0 -40
- data/lib/hanami/validator.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2562e95bb02433bb4b915d900694e888a52d7097b40e10a3337e830d3daf98c
|
4
|
+
data.tar.gz: 54bcb1b523f4966bfa961bd58c9196bafd36e1e9a9d1f57558a8d5f29de5e3cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6e377b7e05589b647d0b51e69d101dfff14a1aa043da684c7166c7e04890c9b5e33a819cdb8f7b83f24bbd5e3b147df1b9179d1236176219f48a0dccf982c7c
|
7
|
+
data.tar.gz: 33157d4d4c3c5bec1b57f5184c710a5e6b4ee89695554354dd4e0f43999eee4effc3a9a3741c7a86485e658860ac310785c96153924400894955c90eb03ec3b1
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
Validations mixin for Ruby objects
|
4
4
|
|
5
|
+
## v2.2.0.beta2 - 2024-09-25
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
- [Tim Riley] Remove all Ruby code from the gem. This gem now exists only to manage the dependency on dry-validation. (#230)
|
10
|
+
|
5
11
|
## v2.2.0.beta1 - 2024-07-16
|
6
12
|
|
7
13
|
### Changed
|
data/hanami-validations.gemspec
CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.required_ruby_version = ">= 3.1"
|
22
22
|
|
23
23
|
spec.add_dependency "dry-validation", ">= 1.10", "< 2"
|
24
|
-
spec.add_dependency "zeitwerk", "~> 2.6.0"
|
25
24
|
|
26
25
|
spec.add_development_dependency "bundler", ">= 1.6", "< 3"
|
27
26
|
spec.add_development_dependency "rake", "~> 13"
|
data/lib/hanami/validations.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "dry/validation"
|
4
|
-
require "delegate"
|
5
|
-
require "zeitwerk"
|
6
4
|
|
7
5
|
# @see Hanami::Validations
|
8
6
|
# @since 0.1.0
|
@@ -10,100 +8,6 @@ module Hanami
|
|
10
8
|
# @since 0.1.0
|
11
9
|
# @api private
|
12
10
|
module Validations
|
13
|
-
# @since 2.0.0
|
14
|
-
# @api private
|
15
|
-
def self.gem_loader
|
16
|
-
@gem_loader ||= Zeitwerk::Loader.new.tap do |loader|
|
17
|
-
root = File.expand_path("..", __dir__)
|
18
|
-
loader.tag = "hanami-validations"
|
19
|
-
loader.inflector = Zeitwerk::GemInflector.new("#{root}/hanami-validations.rb")
|
20
|
-
loader.push_dir(root)
|
21
|
-
loader.ignore(
|
22
|
-
"#{root}/hanami-validations.rb",
|
23
|
-
"#{root}/hanami/validations/version.rb"
|
24
|
-
)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
gem_loader.setup
|
29
11
|
require_relative "validations/version"
|
30
|
-
|
31
|
-
# @since 0.1.0
|
32
|
-
# @api private
|
33
|
-
def self.included(klass)
|
34
|
-
super
|
35
|
-
klass.extend(ClassMethods)
|
36
|
-
end
|
37
|
-
|
38
|
-
# @since 2.0.0
|
39
|
-
# @api private
|
40
|
-
class Result < SimpleDelegator
|
41
|
-
# @since 2.0.0
|
42
|
-
# @api private
|
43
|
-
def output
|
44
|
-
__getobj__.to_h
|
45
|
-
end
|
46
|
-
|
47
|
-
# @since 2.0.0
|
48
|
-
# @api private
|
49
|
-
def messages
|
50
|
-
__getobj__.errors.to_h
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Validations DSL
|
55
|
-
#
|
56
|
-
# @since 0.1.0
|
57
|
-
# @api private
|
58
|
-
module ClassMethods
|
59
|
-
# Define validation rules from the given block.
|
60
|
-
#
|
61
|
-
# @param blk [Proc] validation rules
|
62
|
-
#
|
63
|
-
# @since 0.6.0
|
64
|
-
# @api private
|
65
|
-
def validations(&blk)
|
66
|
-
@_validator = Dry::Validation::Contract.build { schema(&blk) }
|
67
|
-
end
|
68
|
-
|
69
|
-
# @since 2.0.0
|
70
|
-
# @api private
|
71
|
-
def _validator
|
72
|
-
@_validator
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Initialize a new instance of a validator
|
77
|
-
#
|
78
|
-
# @param input [#to_h] a set of input data
|
79
|
-
#
|
80
|
-
# @since 0.6.0
|
81
|
-
# @api private
|
82
|
-
def initialize(input)
|
83
|
-
@input = input
|
84
|
-
end
|
85
|
-
|
86
|
-
# Validates the object.
|
87
|
-
#
|
88
|
-
# @return [Hanami::Validations::Result]
|
89
|
-
#
|
90
|
-
# @since 0.2.4
|
91
|
-
# @api private
|
92
|
-
def validate
|
93
|
-
Result.new(
|
94
|
-
self.class._validator.call(@input)
|
95
|
-
)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Returns a Hash with the defined attributes as symbolized keys, and their
|
99
|
-
# relative values.
|
100
|
-
#
|
101
|
-
# @return [Hash]
|
102
|
-
#
|
103
|
-
# @since 0.1.0
|
104
|
-
# @api private
|
105
|
-
def to_h
|
106
|
-
validate.to_h
|
107
|
-
end
|
108
12
|
end
|
109
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.0.
|
4
|
+
version: 2.2.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-validation
|
@@ -30,20 +30,6 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '2'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: zeitwerk
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 2.6.0
|
40
|
-
type: :runtime
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 2.6.0
|
47
33
|
- !ruby/object:Gem::Dependency
|
48
34
|
name: bundler
|
49
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,9 +105,7 @@ files:
|
|
119
105
|
- hanami-validations.gemspec
|
120
106
|
- lib/hanami-validations.rb
|
121
107
|
- lib/hanami/validations.rb
|
122
|
-
- lib/hanami/validations/form.rb
|
123
108
|
- lib/hanami/validations/version.rb
|
124
|
-
- lib/hanami/validator.rb
|
125
109
|
homepage: http://hanamirb.org
|
126
110
|
licenses:
|
127
111
|
- MIT
|
@@ -142,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
126
|
- !ruby/object:Gem::Version
|
143
127
|
version: '0'
|
144
128
|
requirements: []
|
145
|
-
rubygems_version: 3.5.
|
129
|
+
rubygems_version: 3.5.16
|
146
130
|
signing_key:
|
147
131
|
specification_version: 4
|
148
132
|
summary: Validations mixin for Ruby objects
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
module Validations
|
5
|
-
# Validations mixin for forms/HTTP params.
|
6
|
-
#
|
7
|
-
# @since 0.6.0
|
8
|
-
# @api private
|
9
|
-
module Form
|
10
|
-
# @since 2.0.0
|
11
|
-
# @api private
|
12
|
-
class BaseValidator < Dry::Validation::Contract
|
13
|
-
params do
|
14
|
-
optional(:_csrf_token).filled(:string)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# @since 0.6.0
|
19
|
-
# @api private
|
20
|
-
def self.included(klass)
|
21
|
-
super
|
22
|
-
|
23
|
-
klass.class_eval do
|
24
|
-
include ::Hanami::Validations
|
25
|
-
extend ClassMethods
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# @since 0.6.0
|
30
|
-
# @api private
|
31
|
-
module ClassMethods
|
32
|
-
# @since 2.0.0
|
33
|
-
# @api private
|
34
|
-
def validations(&blk)
|
35
|
-
@_validator = Class.new(BaseValidator) { params(&blk) }.new
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|