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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 214d7269a6988fd34fe6097ea8ae7cf7fc8fc7ed
4
- data.tar.gz: e804d91ebdfdd17544cf88baf7a6ad12d0f91495
3
+ metadata.gz: 762dc2d64c3a0cf8869749bda00023e135f9a901
4
+ data.tar.gz: 2cfb436ac7589b32202d2248a093cd07b89113a4
5
5
  SHA512:
6
- metadata.gz: 65d8ec175b1271eb374f2c3d8134a071966f71dfb28f7de20fb4550db372924f59563f358633c154b50ef2943a4599e740aac656d34ebe972139b697ba377da2
7
- data.tar.gz: bcdabb6bdc7b2dbae1d5d4a07cb87ae62265b56f0302b80c27eeb3a0232244bf944e9d1b2902a6f34cb4759a4b30356ae30459163788cd27e7a5675bd44b14c1
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
@@ -1,3 +1,3 @@
1
1
  module Validate
2
- VERSION = '1.3.2'
2
+ VERSION = '1.3.3'
3
3
  end
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.2
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