validate 1.3.2 → 1.3.3
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 +4 -4
- data/lib/validate/kenji.rb +39 -0
- data/lib/validate/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 762dc2d64c3a0cf8869749bda00023e135f9a901
|
4
|
+
data.tar.gz: 2cfb436ac7589b32202d2248a093cd07b89113a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb48a9ffccf6cc849d6c3912665a867353fb086b41e12f581c4f45743472f0c39da214e489b066bda26fb566627427c78ab37d73625331ab9d9612c01d1bed3f
|
7
|
+
data.tar.gz: 531ba376b22ad2ae46d37b7df17c99d4020d9c4b6dfa0daafdda3e6b9012b330b96a531f04c47defb4cac849aca27ce4ec08f66c8b96296ef0e5773b7b8fcab4
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'kenji'
|
2
|
+
require 'validate'
|
3
|
+
require 'validate/hash'
|
4
|
+
|
5
|
+
# This extention provides an easier way to utilize Validate's functionality
|
6
|
+
# from the Kenji web framework.
|
7
|
+
#
|
8
|
+
# For example, one might do:
|
9
|
+
#
|
10
|
+
# # a kenji route
|
11
|
+
# post '/login' do
|
12
|
+
# input = kenji.validated_input do
|
13
|
+
# validates_type_of 'email', is: String
|
14
|
+
# validates_type_of 'password', is: String
|
15
|
+
# end
|
16
|
+
# # from here on out I can assume input is valid...
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
module Kenji
|
20
|
+
|
21
|
+
class Kenji
|
22
|
+
|
23
|
+
# This method takes a validations block. The request input is grabbed from
|
24
|
+
# Kenji, and tested against the validations. In case the validations fail,
|
25
|
+
# the request is aborted and returns with a 400 error.
|
26
|
+
#
|
27
|
+
# Note: the validations will be parsed each time, which is a little bit
|
28
|
+
# inefficient. TODO: fix this.
|
29
|
+
#
|
30
|
+
def validated_input(&block)
|
31
|
+
validations = Validate::Parser.parse(&block)
|
32
|
+
input = self.input_as_json
|
33
|
+
unless input.validates?(validations)
|
34
|
+
self.respond(400, 'Invalid input.', failures: input.failures)
|
35
|
+
end
|
36
|
+
input
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/validate/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenneth Ballenegger
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- Rakefile
|
39
39
|
- lib/validate.rb
|
40
40
|
- lib/validate/hash.rb
|
41
|
+
- lib/validate/kenji.rb
|
41
42
|
- lib/validate/kongo.rb
|
42
43
|
- lib/validate/parser.rb
|
43
44
|
- lib/validate/validations.rb
|