hanami-validations 1.0.0.beta1 → 1.0.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 +2 -0
- data/LICENSE.md +1 -1
- data/README.md +3 -3
- data/lib/hanami/validations.rb +21 -10
- data/lib/hanami/validations/predicates.rb +1 -1
- data/lib/hanami/validations/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11ba5bd5d5dd82bd7d723d7bad916028703973d5
|
4
|
+
data.tar.gz: c721ce2fe3e43b0ce9871665067b1f1c8a63258f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9e0c5073c472ac6237c4a214f77164a0d717c7603c4fc545de6261b055cbf57e4c1f5bad7442920796c9e50ed955f4ff599e349fd718ee8813042256a2ef612
|
7
|
+
data.tar.gz: d27480a8a99a337a7673d303dfe70a2c36bd81555595f9938ab5360c813a1877fd5008ba6116636e226e4485c24e60758a2a4ba5ec5c7c320cd9728ff8a2a15c
|
data/CHANGELOG.md
CHANGED
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -682,11 +682,11 @@ To be used like this:
|
|
682
682
|
class SignupValidator
|
683
683
|
include Hanami::Validations
|
684
684
|
messages_path 'config/messages.yml'
|
685
|
-
|
685
|
+
|
686
686
|
predicate :email? do |current|
|
687
687
|
# ...
|
688
688
|
end
|
689
|
-
|
689
|
+
|
690
690
|
validations do
|
691
691
|
required(:email).filled(:str?, :email?)
|
692
692
|
required(:age).filled(:int?, gt?: 18)
|
@@ -798,6 +798,6 @@ Thanks to [dry-rb](http://dry-rb.org) Community for their priceless support. ❤
|
|
798
798
|
|
799
799
|
## Copyright
|
800
800
|
|
801
|
-
Copyright © 2014-
|
801
|
+
Copyright © 2014-2017 Luca Guidi – Released under MIT License
|
802
802
|
|
803
803
|
This project was formerly known as Lotus (`lotus-validations`).
|
data/lib/hanami/validations.rb
CHANGED
@@ -11,6 +11,7 @@ Dry::Validation::Messages::Namespaced.configure do |config|
|
|
11
11
|
).freeze
|
12
12
|
end
|
13
13
|
|
14
|
+
# @since 0.1.0
|
14
15
|
module Hanami
|
15
16
|
# Hanami::Validations is a set of lightweight validations for Ruby objects.
|
16
17
|
#
|
@@ -39,8 +40,7 @@ module Hanami
|
|
39
40
|
# @api private
|
40
41
|
#
|
41
42
|
# @see http://www.ruby-doc.org/core/Module.html#method-i-included
|
42
|
-
# rubocop:disable Metrics/MethodLength
|
43
|
-
def self.included(base)
|
43
|
+
def self.included(base) # rubocop:disable Metrics/MethodLength
|
44
44
|
base.class_eval do
|
45
45
|
extend ClassMethods
|
46
46
|
|
@@ -55,7 +55,6 @@ module Hanami
|
|
55
55
|
self._predicates = Set.new
|
56
56
|
end
|
57
57
|
end
|
58
|
-
# rubocop:enable Metrics/MethodLength
|
59
58
|
|
60
59
|
# Validations DSL
|
61
60
|
#
|
@@ -67,7 +66,9 @@ module Hanami
|
|
67
66
|
#
|
68
67
|
# @since 0.6.0
|
69
68
|
#
|
70
|
-
# @
|
69
|
+
# @see http://hanamirb.org/guides/validations/overview/
|
70
|
+
#
|
71
|
+
# @example Basic Example
|
71
72
|
# require 'hanami/validations'
|
72
73
|
#
|
73
74
|
# class Signup
|
@@ -78,8 +79,18 @@ module Hanami
|
|
78
79
|
# end
|
79
80
|
# end
|
80
81
|
#
|
81
|
-
#
|
82
|
-
|
82
|
+
# result = Signup.new(name: "Luca").validate
|
83
|
+
#
|
84
|
+
# result.success? # => true
|
85
|
+
# result.messages # => []
|
86
|
+
# result.output # => {:name=>""}
|
87
|
+
#
|
88
|
+
# result = Signup.new(name: "").validate
|
89
|
+
#
|
90
|
+
# result.success? # => false
|
91
|
+
# result.messages # => {:name=>["must be filled"]}
|
92
|
+
# result.output # => {:name=>""}
|
93
|
+
def validations(&blk) # rubocop:disable Metrics/AbcSize
|
83
94
|
schema_predicates = _predicates_module || __predicates
|
84
95
|
|
85
96
|
base = _build(predicates: schema_predicates, &_base_rules)
|
@@ -90,7 +101,6 @@ module Hanami
|
|
90
101
|
|
91
102
|
self.schema = schema.new
|
92
103
|
end
|
93
|
-
# rubocop:enable Metrics/AbcSize
|
94
104
|
|
95
105
|
# Define an inline predicate
|
96
106
|
#
|
@@ -300,15 +310,16 @@ module Hanami
|
|
300
310
|
|
301
311
|
# @since 0.6.0
|
302
312
|
# @api private
|
303
|
-
# rubocop:disable Metrics/MethodLength
|
304
|
-
def __messages
|
313
|
+
def __messages # rubocop:disable Metrics/MethodLength
|
305
314
|
result = _predicates.each_with_object({}) do |p, ret|
|
306
315
|
ret[p.name] = p.message
|
307
316
|
end
|
308
317
|
|
318
|
+
# @api private
|
309
319
|
Module.new do
|
310
320
|
@@__messages = result # rubocop:disable Style/ClassVars
|
311
321
|
|
322
|
+
# @api private
|
312
323
|
def self.extended(base)
|
313
324
|
base.instance_eval do
|
314
325
|
def __messages
|
@@ -317,6 +328,7 @@ module Hanami
|
|
317
328
|
end
|
318
329
|
end
|
319
330
|
|
331
|
+
# @api private
|
320
332
|
def messages
|
321
333
|
engine = super
|
322
334
|
|
@@ -328,7 +340,6 @@ module Hanami
|
|
328
340
|
end
|
329
341
|
end
|
330
342
|
end
|
331
|
-
# rubocop:enable Metrics/MethodLength
|
332
343
|
end
|
333
344
|
|
334
345
|
# Initialize a new instance of a validator
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-03-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hanami-utils
|