hanami-validations 1.3.7 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +99 -0
- data/README.md +262 -568
- data/hanami-validations.gemspec +4 -6
- data/lib/hanami/validations/form.rb +26 -20
- data/lib/hanami/validations/version.rb +1 -1
- data/lib/hanami/validations.rb +35 -311
- data/lib/hanami/validator.rb +9 -0
- metadata +18 -60
- data/lib/hanami/validations/inline_predicate.rb +0 -48
- data/lib/hanami/validations/namespace.rb +0 -67
- data/lib/hanami/validations/predicates.rb +0 -47
- data/lib/hanami-validations.rb +0 -3
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
module Validations
|
5
|
-
# Inline predicate
|
6
|
-
#
|
7
|
-
# @since 0.6.0
|
8
|
-
# @api private
|
9
|
-
class InlinePredicate
|
10
|
-
# @since 0.6.0
|
11
|
-
# @api private
|
12
|
-
attr_reader :name
|
13
|
-
|
14
|
-
# @since 0.6.0
|
15
|
-
# @api private
|
16
|
-
attr_reader :message
|
17
|
-
|
18
|
-
# Return a new instance.
|
19
|
-
#
|
20
|
-
# @param name [Symbol] inline predicate name
|
21
|
-
# @param message [String] optional failure message
|
22
|
-
# @param blk [Proc] predicate implementation
|
23
|
-
#
|
24
|
-
# @return [Hanami::Validations::InlinePredicate] a new instance
|
25
|
-
#
|
26
|
-
# @since 0.6.0
|
27
|
-
# @api private
|
28
|
-
def initialize(name, message, &blk)
|
29
|
-
@name = name
|
30
|
-
@message = message
|
31
|
-
@blk = blk
|
32
|
-
end
|
33
|
-
|
34
|
-
# @since 0.6.0
|
35
|
-
# @api private
|
36
|
-
def to_proc
|
37
|
-
@blk
|
38
|
-
end
|
39
|
-
|
40
|
-
# @since 0.6.0
|
41
|
-
# @api private
|
42
|
-
def ==(other)
|
43
|
-
self.class == other.class &&
|
44
|
-
name == other.name
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "hanami/utils/string"
|
4
|
-
|
5
|
-
module Hanami
|
6
|
-
module Validations
|
7
|
-
# Validations message namespace.
|
8
|
-
#
|
9
|
-
# For a given `FooValidator` class, it will look for I18n messages within
|
10
|
-
# the `foo` group.
|
11
|
-
#
|
12
|
-
# @since 0.6.0
|
13
|
-
# @api private
|
14
|
-
class Namespace
|
15
|
-
# @since 0.6.0
|
16
|
-
# @api private
|
17
|
-
SUFFIX = "Validator"
|
18
|
-
|
19
|
-
# @since 0.6.0
|
20
|
-
# @api private
|
21
|
-
SUFFIX_REPLACEMENT = ""
|
22
|
-
|
23
|
-
# @since 0.6.0
|
24
|
-
# @api private
|
25
|
-
RUBY_NAMESPACE_SEPARATOR = "/"
|
26
|
-
|
27
|
-
# @since 0.6.0
|
28
|
-
# @api private
|
29
|
-
RUBY_NAMESPACE_REPLACEMENT = "."
|
30
|
-
|
31
|
-
# @since 0.6.0
|
32
|
-
# @api private
|
33
|
-
def self.new(name, klass)
|
34
|
-
result = name || klass.name
|
35
|
-
return nil if result.nil?
|
36
|
-
|
37
|
-
super(result)
|
38
|
-
end
|
39
|
-
|
40
|
-
# @since 0.6.0
|
41
|
-
# @api private
|
42
|
-
def initialize(name)
|
43
|
-
@name = name
|
44
|
-
end
|
45
|
-
|
46
|
-
# @since 0.6.0
|
47
|
-
# @api private
|
48
|
-
def to_s
|
49
|
-
underscored_name.gsub(RUBY_NAMESPACE_SEPARATOR, RUBY_NAMESPACE_REPLACEMENT)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
# @since 0.6.0
|
55
|
-
# @api private
|
56
|
-
def underscored_name
|
57
|
-
Utils::String.underscore(name_without_suffix)
|
58
|
-
end
|
59
|
-
|
60
|
-
# @since 0.6.0
|
61
|
-
# @api private
|
62
|
-
def name_without_suffix
|
63
|
-
@name.sub(SUFFIX, SUFFIX_REPLACEMENT)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "dry/logic/predicates"
|
4
|
-
require "hanami/utils/class_attribute"
|
5
|
-
|
6
|
-
module Hanami
|
7
|
-
module Validations
|
8
|
-
# Mixin to include when defining shared predicates
|
9
|
-
#
|
10
|
-
# @since 0.6.0
|
11
|
-
#
|
12
|
-
# @see Hanami::Validations::ClassMethods#predicates
|
13
|
-
#
|
14
|
-
# @example Inline Predicate
|
15
|
-
# require 'hanami/validations'
|
16
|
-
#
|
17
|
-
# module MySharedPredicates
|
18
|
-
# include Hanami::Validations::Predicates
|
19
|
-
#
|
20
|
-
# predicate :foo? do |actual|
|
21
|
-
# actual == 'foo'
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# class MyValidator
|
26
|
-
# include Hanami::Validations
|
27
|
-
# predicates MySharedPredicates
|
28
|
-
#
|
29
|
-
# validations do
|
30
|
-
# required(:name).filled(:foo?)
|
31
|
-
# end
|
32
|
-
# end
|
33
|
-
module Predicates
|
34
|
-
# @since 0.6.0
|
35
|
-
# @api private
|
36
|
-
def self.included(base)
|
37
|
-
base.class_eval do
|
38
|
-
include Dry::Logic::Predicates
|
39
|
-
include Utils::ClassAttribute
|
40
|
-
|
41
|
-
class_attribute :messages
|
42
|
-
class_attribute :messages_path
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/hanami-validations.rb
DELETED