hanami-validations 1.3.6 → 2.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -5
- data/README.md +259 -568
- data/hanami-validations.gemspec +17 -17
- data/lib/hanami/validations.rb +37 -311
- data/lib/hanami/validations/form.rb +27 -19
- data/lib/hanami/validations/version.rb +3 -2
- data/lib/hanami/validator.rb +9 -0
- metadata +11 -54
- data/lib/hanami-validations.rb +0 -1
- data/lib/hanami/validations/inline_predicate.rb +0 -46
- data/lib/hanami/validations/namespace.rb +0 -65
- data/lib/hanami/validations/predicates.rb +0 -45
metadata
CHANGED
@@ -1,69 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.alpha1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: hanami-utils
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.3'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.3'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: dry-validation
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
34
|
-
- - "<"
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: '0.12'
|
19
|
+
version: '1.0'
|
37
20
|
type: :runtime
|
38
21
|
prerelease: false
|
39
22
|
version_requirements: !ruby/object:Gem::Requirement
|
40
23
|
requirements:
|
41
24
|
- - "~>"
|
42
25
|
- !ruby/object:Gem::Version
|
43
|
-
version: '0
|
44
|
-
- - "<"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0.12'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: dry-logic
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 0.4.2
|
54
|
-
- - "<"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '0.5'
|
57
|
-
type: :runtime
|
58
|
-
prerelease: false
|
59
|
-
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - "~>"
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: 0.4.2
|
64
|
-
- - "<"
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '0.5'
|
26
|
+
version: '1.0'
|
67
27
|
- !ruby/object:Gem::Dependency
|
68
28
|
name: bundler
|
69
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,14 +50,14 @@ dependencies:
|
|
90
50
|
requirements:
|
91
51
|
- - "~>"
|
92
52
|
- !ruby/object:Gem::Version
|
93
|
-
version: '
|
53
|
+
version: '12'
|
94
54
|
type: :development
|
95
55
|
prerelease: false
|
96
56
|
version_requirements: !ruby/object:Gem::Requirement
|
97
57
|
requirements:
|
98
58
|
- - "~>"
|
99
59
|
- !ruby/object:Gem::Version
|
100
|
-
version: '
|
60
|
+
version: '12'
|
101
61
|
- !ruby/object:Gem::Dependency
|
102
62
|
name: rspec
|
103
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,13 +83,10 @@ files:
|
|
123
83
|
- LICENSE.md
|
124
84
|
- README.md
|
125
85
|
- hanami-validations.gemspec
|
126
|
-
- lib/hanami-validations.rb
|
127
86
|
- lib/hanami/validations.rb
|
128
87
|
- lib/hanami/validations/form.rb
|
129
|
-
- lib/hanami/validations/inline_predicate.rb
|
130
|
-
- lib/hanami/validations/namespace.rb
|
131
|
-
- lib/hanami/validations/predicates.rb
|
132
88
|
- lib/hanami/validations/version.rb
|
89
|
+
- lib/hanami/validator.rb
|
133
90
|
homepage: http://hanamirb.org
|
134
91
|
licenses:
|
135
92
|
- MIT
|
@@ -142,14 +99,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
99
|
requirements:
|
143
100
|
- - ">="
|
144
101
|
- !ruby/object:Gem::Version
|
145
|
-
version: 2.
|
102
|
+
version: 2.4.0
|
146
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
104
|
requirements:
|
148
|
-
- - "
|
105
|
+
- - ">"
|
149
106
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
107
|
+
version: 1.3.1
|
151
108
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
109
|
+
rubygems_version: 3.0.3
|
153
110
|
signing_key:
|
154
111
|
specification_version: 4
|
155
112
|
summary: Validations mixin for Ruby objects
|
data/lib/hanami-validations.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'hanami/validations'
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
module Validations
|
3
|
-
# Inline predicate
|
4
|
-
#
|
5
|
-
# @since 0.6.0
|
6
|
-
# @api private
|
7
|
-
class InlinePredicate
|
8
|
-
# @since 0.6.0
|
9
|
-
# @api private
|
10
|
-
attr_reader :name
|
11
|
-
|
12
|
-
# @since 0.6.0
|
13
|
-
# @api private
|
14
|
-
attr_reader :message
|
15
|
-
|
16
|
-
# Return a new instance.
|
17
|
-
#
|
18
|
-
# @param name [Symbol] inline predicate name
|
19
|
-
# @param message [String] optional failure message
|
20
|
-
# @param blk [Proc] predicate implementation
|
21
|
-
#
|
22
|
-
# @return [Hanami::Validations::InlinePredicate] a new instance
|
23
|
-
#
|
24
|
-
# @since 0.6.0
|
25
|
-
# @api private
|
26
|
-
def initialize(name, message, &blk)
|
27
|
-
@name = name
|
28
|
-
@message = message
|
29
|
-
@blk = blk
|
30
|
-
end
|
31
|
-
|
32
|
-
# @since 0.6.0
|
33
|
-
# @api private
|
34
|
-
def to_proc
|
35
|
-
@blk
|
36
|
-
end
|
37
|
-
|
38
|
-
# @since 0.6.0
|
39
|
-
# @api private
|
40
|
-
def ==(other)
|
41
|
-
self.class == other.class &&
|
42
|
-
name == other.name
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'hanami/utils/string'
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
module Validations
|
5
|
-
# Validations message namespace.
|
6
|
-
#
|
7
|
-
# For a given `FooValidator` class, it will look for I18n messages within
|
8
|
-
# the `foo` group.
|
9
|
-
#
|
10
|
-
# @since 0.6.0
|
11
|
-
# @api private
|
12
|
-
class Namespace
|
13
|
-
# @since 0.6.0
|
14
|
-
# @api private
|
15
|
-
SUFFIX = 'Validator'.freeze
|
16
|
-
|
17
|
-
# @since 0.6.0
|
18
|
-
# @api private
|
19
|
-
SUFFIX_REPLACEMENT = ''.freeze
|
20
|
-
|
21
|
-
# @since 0.6.0
|
22
|
-
# @api private
|
23
|
-
RUBY_NAMESPACE_SEPARATOR = '/'.freeze
|
24
|
-
|
25
|
-
# @since 0.6.0
|
26
|
-
# @api private
|
27
|
-
RUBY_NAMESPACE_REPLACEMENT = '.'.freeze
|
28
|
-
|
29
|
-
# @since 0.6.0
|
30
|
-
# @api private
|
31
|
-
def self.new(name, klass)
|
32
|
-
result = name || klass.name
|
33
|
-
return nil if result.nil?
|
34
|
-
|
35
|
-
super(result)
|
36
|
-
end
|
37
|
-
|
38
|
-
# @since 0.6.0
|
39
|
-
# @api private
|
40
|
-
def initialize(name)
|
41
|
-
@name = name
|
42
|
-
end
|
43
|
-
|
44
|
-
# @since 0.6.0
|
45
|
-
# @api private
|
46
|
-
def to_s
|
47
|
-
underscored_name.gsub(RUBY_NAMESPACE_SEPARATOR, RUBY_NAMESPACE_REPLACEMENT)
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
# @since 0.6.0
|
53
|
-
# @api private
|
54
|
-
def underscored_name
|
55
|
-
Utils::String.underscore(name_without_suffix)
|
56
|
-
end
|
57
|
-
|
58
|
-
# @since 0.6.0
|
59
|
-
# @api private
|
60
|
-
def name_without_suffix
|
61
|
-
@name.sub(SUFFIX, SUFFIX_REPLACEMENT)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
require 'hanami/utils/class_attribute'
|
3
|
-
|
4
|
-
module Hanami
|
5
|
-
module Validations
|
6
|
-
# Mixin to include when defining shared predicates
|
7
|
-
#
|
8
|
-
# @since 0.6.0
|
9
|
-
#
|
10
|
-
# @see Hanami::Validations::ClassMethods#predicates
|
11
|
-
#
|
12
|
-
# @example Inline Predicate
|
13
|
-
# require 'hanami/validations'
|
14
|
-
#
|
15
|
-
# module MySharedPredicates
|
16
|
-
# include Hanami::Validations::Predicates
|
17
|
-
#
|
18
|
-
# predicate :foo? do |actual|
|
19
|
-
# actual == 'foo'
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# class MyValidator
|
24
|
-
# include Hanami::Validations
|
25
|
-
# predicates MySharedPredicates
|
26
|
-
#
|
27
|
-
# validations do
|
28
|
-
# required(:name).filled(:foo?)
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
module Predicates
|
32
|
-
# @since 0.6.0
|
33
|
-
# @api private
|
34
|
-
def self.included(base)
|
35
|
-
base.class_eval do
|
36
|
-
include Dry::Logic::Predicates
|
37
|
-
include Utils::ClassAttribute
|
38
|
-
|
39
|
-
class_attribute :messages
|
40
|
-
class_attribute :messages_path
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|