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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99ff96a9cb4892a83e5856bc634d177c66d6f37c
4
- data.tar.gz: f0ecb809653141a79d11829105c67d9d1ed3df23
3
+ metadata.gz: 11ba5bd5d5dd82bd7d723d7bad916028703973d5
4
+ data.tar.gz: c721ce2fe3e43b0ce9871665067b1f1c8a63258f
5
5
  SHA512:
6
- metadata.gz: c2290ef3644c39145c4c98278881acab876ba15ba73b85a5de6e597d111a9cd64cd27801067ddcfaa4c42922ccdd513e056d6181c8b8b296f0543e0e4b74c2d4
7
- data.tar.gz: 4f5e9e1c02ed5565329c26f029984b02112b0744de1a21e5bdf96e4953ff410de916aff632721b5327ea33be8813b7b42d2fde4fed232839b1ff7ff7f792508d
6
+ metadata.gz: b9e0c5073c472ac6237c4a214f77164a0d717c7603c4fc545de6261b055cbf57e4c1f5bad7442920796c9e50ed955f4ff599e349fd718ee8813042256a2ef612
7
+ data.tar.gz: d27480a8a99a337a7673d303dfe70a2c36bd81555595f9938ab5360c813a1877fd5008ba6116636e226e4485c24e60758a2a4ba5ec5c7c320cd9728ff8a2a15c
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Hanami::Validations
2
2
  Validations mixin for Ruby objects
3
3
 
4
+ ## v1.0.0.beta2 - 2017-03-17
5
+
4
6
  ## v1.0.0.beta1 - 2017-02-14
5
7
  ### Added
6
8
  - [Luca Guidi] Official support for Ruby: MRI 2.4
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright © 2014-2016 Luca Guidi
1
+ Copyright © 2014-2017 Luca Guidi
2
2
 
3
3
  MIT License
4
4
 
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-2016 Luca Guidi – Released under MIT License
801
+ Copyright © 2014-2017 Luca Guidi – Released under MIT License
802
802
 
803
803
  This project was formerly known as Lotus (`lotus-validations`).
@@ -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
- # @example
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
- # rubocop:disable Metrics/AbcSize
82
- def validations(&blk)
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
@@ -9,7 +9,7 @@ module Hanami
9
9
  #
10
10
  # @see Hanami::Validations::ClassMethods#predicates
11
11
  #
12
- # @example
12
+ # @example Inline Predicate
13
13
  # require 'hanami/validations'
14
14
  #
15
15
  # module MySharedPredicates
@@ -1,6 +1,6 @@
1
1
  module Hanami
2
2
  module Validations
3
3
  # @since 0.1.0
4
- VERSION = '1.0.0.beta1'.freeze
4
+ VERSION = '1.0.0.beta2'.freeze
5
5
  end
6
6
  end
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.beta1
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-02-14 00:00:00.000000000 Z
13
+ date: 2017-03-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hanami-utils