veto 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -94
- data/lib/veto/blocks/block.rb +25 -0
- data/lib/veto/blocks/checker.rb +28 -0
- data/lib/veto/blocks/conditional_block.rb +26 -0
- data/lib/veto/blocks/validate_block.rb +18 -0
- data/lib/veto/blocks/validates_block.rb +51 -0
- data/lib/veto/blocks/with_options_block.rb +7 -0
- data/lib/veto/check_context_object.rb +10 -0
- data/lib/veto/checks/attribute_check.rb +19 -0
- data/lib/veto/checks/check.rb +7 -0
- data/lib/veto/checks/check_factory.rb +18 -0
- data/lib/veto/{validators/exact_length_validator.rb → checks/exact_length_check.rb} +5 -4
- data/lib/veto/{validators/format_validator.rb → checks/format_check.rb} +5 -4
- data/lib/veto/{validators/greater_than_validator.rb → checks/greater_than_check.rb} +2 -4
- data/lib/veto/{validators/greater_than_or_equal_to_validator.rb → checks/greater_than_or_equal_to_check.rb} +2 -4
- data/lib/veto/{validators/inclusion_validator.rb → checks/inclusion_check.rb} +2 -4
- data/lib/veto/{validators/integer_validator.rb → checks/integer_check.rb} +2 -4
- data/lib/veto/{validators/length_range_validator.rb → checks/length_range_check.rb} +2 -4
- data/lib/veto/{validators/less_than_validator.rb → checks/less_than_check.rb} +2 -4
- data/lib/veto/{validators/less_than_or_equal_to_validator.rb → checks/less_than_or_equal_to_check.rb} +2 -4
- data/lib/veto/{validators/max_length_validator.rb → checks/max_length_check.rb} +2 -4
- data/lib/veto/checks/method_check.rb +17 -0
- data/lib/veto/{validators/min_length_validator.rb → checks/min_length_check.rb} +2 -4
- data/lib/veto/{validators/not_null_validator.rb → checks/not_null_check.rb} +2 -4
- data/lib/veto/{validators/numeric_validator.rb → checks/numeric_check.rb} +2 -4
- data/lib/veto/{validators/presence_validator.rb → checks/presence_check.rb} +2 -4
- data/lib/veto/conditions/condition.rb +7 -0
- data/lib/veto/conditions/condition_factory.rb +18 -0
- data/lib/veto/conditions/conditions.rb +21 -0
- data/lib/veto/conditions/context_method_condition.rb +11 -0
- data/lib/veto/conditions/entity_eval_condition.rb +11 -0
- data/lib/veto/conditions/if_conditions.rb +8 -0
- data/lib/veto/conditions/if_unless_conditions.rb +21 -0
- data/lib/veto/conditions/passing_condition.rb +7 -0
- data/lib/veto/conditions/primative_condition.rb +11 -0
- data/lib/veto/conditions/proc_condition.rb +11 -0
- data/lib/veto/conditions/unless_conditions.rb +8 -0
- data/lib/veto/configuration.rb +38 -37
- data/lib/veto/errors.rb +27 -27
- data/lib/veto/exceptions.rb +13 -3
- data/lib/veto/model.rb +33 -35
- data/lib/veto/validator.rb +68 -169
- data/lib/veto/version.rb +1 -1
- data/lib/veto.rb +90 -49
- data/spec/blocks/block_spec.rb +31 -0
- data/spec/blocks/check_block_spec.rb +46 -0
- data/spec/blocks/conditional_block_spec.rb +36 -0
- data/spec/blocks/validate_block_spec.rb +18 -0
- data/spec/blocks/validates_block_spec.rb +22 -0
- data/spec/checks/exact_length_check_spec.rb +37 -0
- data/spec/checks/format_validator_spec.rb +37 -0
- data/spec/checks/greater_than_check_spec.rb +48 -0
- data/spec/checks/greater_than_or_equal_to_check_spec.rb +48 -0
- data/spec/checks/inclusion_check_spec.rb +37 -0
- data/spec/checks/integer_check_spec.rb +37 -0
- data/spec/checks/length_range_check_spec.rb +37 -0
- data/spec/checks/less_than_check_spec.rb +48 -0
- data/spec/checks/less_than_or_equal_to_check_spec.rb +48 -0
- data/spec/checks/max_length_check_spec.rb +48 -0
- data/spec/checks/method_check_spec.rb +13 -0
- data/spec/checks/min_length_check_spec.rb +48 -0
- data/spec/checks/not_null_check_spec.rb +37 -0
- data/spec/checks/numeric_check_spec.rb +37 -0
- data/spec/checks/presence_check_spec.rb +48 -0
- data/spec/conditions/condition_factory_spec.rb +31 -0
- data/spec/conditions/conditions_spec.rb +25 -0
- data/spec/conditions/context_method_condition_spec.rb +25 -0
- data/spec/conditions/entity_eval_condition_spec.rb +21 -0
- data/spec/conditions/if_conditions_spec.rb +65 -0
- data/spec/conditions/if_unless_conditions_spec.rb +33 -0
- data/spec/conditions/primative_condition_spec.rb +22 -0
- data/spec/conditions/proc_condition_spec.rb +25 -0
- data/spec/conditions/unless_conditions_spec.rb +65 -0
- data/spec/configuration/message_spec.rb +18 -23
- data/spec/spec_helper.rb +2 -1
- data/spec/validator_spec.rb +224 -115
- metadata +96 -61
- data/lib/veto/attribute_validator_factory.rb +0 -36
- data/lib/veto/builder.rb +0 -65
- data/lib/veto/conditions.rb +0 -23
- data/lib/veto/conditions_evaluator.rb +0 -30
- data/lib/veto/validators/abstract_validator.rb +0 -15
- data/lib/veto/validators/attribute_validator.rb +0 -22
- data/lib/veto/validators/custom_method_validator.rb +0 -19
- data/spec/attribute_validator_factory_spec.rb +0 -72
- data/spec/builder_spec.rb +0 -38
- data/spec/conditions_evaluator_spec.rb +0 -90
- data/spec/conditions_spec.rb +0 -16
- data/spec/configuration_spec.rb +0 -6
- data/spec/errors_spec.rb +0 -22
- data/spec/model_spec.rb +0 -67
- data/spec/system/validator_spec.rb +0 -530
- data/spec/validators/exact_length_validator_spec.rb +0 -37
- data/spec/validators/format_validator_spec.rb +0 -32
- data/spec/validators/inclusion_validator_spec.rb +0 -45
- data/spec/validators/integer_validator_spec.rb +0 -42
- data/spec/validators/length_range_validator_spec.rb +0 -55
- data/spec/validators/max_length_validator_spec.rb +0 -32
- data/spec/validators/min_length_validator_spec.rb +0 -32
- data/spec/validators/not_null_validator_spec.rb +0 -27
- data/spec/validators/numeric_validator_spec.rb +0 -42
- data/spec/validators/presence_validator_spec.rb +0 -47
- data/spec/veto_spec.rb +0 -24
data/lib/veto/configuration.rb
CHANGED
@@ -1,46 +1,47 @@
|
|
1
1
|
module Veto
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
2
|
+
class Configuration
|
3
|
+
class Message
|
4
|
+
DEFAULT_MESSAGES = {
|
5
|
+
:default => lambda {"is not valid"},
|
6
|
+
:exact_length => lambda {|exact| "is not #{exact} characters"},
|
7
|
+
:format => lambda {"is not valid"},
|
8
|
+
:greater_than => lambda {|boundary| "must be greater than #{boundary}"},
|
9
|
+
:greater_than_or_equal_to => lambda {|boundary| "must be greater than or equal to #{boundary}"},
|
10
|
+
:inclusion => lambda {|set| "is not in set: #{set.inspect}"},
|
11
|
+
:integer => lambda {"is not a number"},
|
12
|
+
:length_range => lambda {"is too short or too long"},
|
13
|
+
:less_than => lambda {|boundary| "must be less than #{boundary}"},
|
14
|
+
:less_than_or_equal_to => lambda {|boundary| "must be less than or equal to #{boundary}"},
|
15
|
+
:max_length => lambda {|max| "is longer than #{max} characters"},
|
16
|
+
:min_length => lambda {|min| "is shorter than #{min} characters"},
|
17
|
+
:not_null => lambda {"is not present"},
|
18
|
+
:numeric => lambda {"is not a number"},
|
19
|
+
:presence => lambda {"is not present"}
|
20
|
+
}
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
def initialize
|
23
|
+
@messages = {}
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
def get(type, *args)
|
27
|
+
args.compact.length > 0 ? message(type).call(*args) : message(type).call
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
+
def set(type, proc)
|
31
|
+
@messages[type] = proc
|
32
|
+
end
|
30
33
|
|
31
|
-
|
32
|
-
@custom_messages ||= {}
|
33
|
-
end
|
34
|
+
private
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
def message(type)
|
37
|
+
@messages[type] || DEFAULT_MESSAGES[type] || DEFAULT_MESSAGES[:default]
|
38
|
+
end
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
+
attr_reader :message
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
def initialize
|
44
|
+
@message = Message.new
|
45
|
+
end
|
46
|
+
end
|
46
47
|
end
|
data/lib/veto/errors.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
module Veto
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
class Errors < ::Hash
|
3
|
+
def add(atr, msg, *msg_opts)
|
4
|
+
fetch(atr){self[atr] = []} << msg_lookup(msg, *msg_opts)
|
5
|
+
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def count
|
8
|
+
values.inject(0){|m, v| m + v.length}
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def empty?
|
12
|
+
count == 0
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
def full_messages
|
16
|
+
inject([]) do |m, kv|
|
17
|
+
atr, errors = *kv
|
18
|
+
errors.each {|e| m << "#{atr} #{e}"}
|
19
|
+
m
|
20
|
+
end
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
def on(atr)
|
24
|
+
if v = fetch(atr, nil) and !v.empty?
|
25
|
+
v
|
26
|
+
end
|
27
|
+
end
|
28
28
|
|
29
|
-
|
29
|
+
private
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
def msg_lookup(msg, *msg_opts)
|
32
|
+
msg.is_a?(Symbol) ? ::Veto.configuration.message.get(msg, *msg_opts) : msg
|
33
|
+
end
|
34
|
+
end
|
35
35
|
end
|
data/lib/veto/exceptions.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
module Veto
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class VetoError < StandardError; end
|
3
|
+
|
4
|
+
class CheckNotAssigned < VetoError; end
|
5
|
+
|
6
|
+
class InvalidEntity < VetoError
|
7
|
+
def initialize(errors)
|
8
|
+
@errors = errors
|
9
|
+
end
|
10
|
+
|
11
|
+
def message
|
12
|
+
@errors.full_messages
|
13
|
+
end
|
14
|
+
end
|
5
15
|
end
|
data/lib/veto/model.rb
CHANGED
@@ -1,37 +1,35 @@
|
|
1
|
-
require 'veto/exceptions'
|
2
|
-
|
3
1
|
module Veto
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
2
|
+
module Model
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def validates_with(veto_validator)
|
9
|
+
@validator = veto_validator
|
10
|
+
end
|
11
|
+
|
12
|
+
def validator
|
13
|
+
@validator || raise(::Veto::ValidatorNotAssigned, 'validator not assigned')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
validator.valid?(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def validate!
|
22
|
+
validator.validate!(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
def errors
|
26
|
+
validator.errors
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def validator
|
32
|
+
self.class.validator
|
33
|
+
end
|
34
|
+
end
|
37
35
|
end
|
data/lib/veto/validator.rb
CHANGED
@@ -1,171 +1,70 @@
|
|
1
|
-
require 'veto/errors'
|
2
|
-
require 'veto/exceptions'
|
3
|
-
require 'veto/builder'
|
4
|
-
|
5
1
|
module Veto
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
def builder
|
76
|
-
@builder ||= ::Veto::Builder.new(self)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Ensures that when a Validator class is subclassed, the
|
80
|
-
# validation rules will be carried into the subclass as well,
|
81
|
-
# where they may be added upon.
|
82
|
-
#
|
83
|
-
# @example
|
84
|
-
# class PersonValidator
|
85
|
-
# include Veto.validator
|
86
|
-
# validates :name, :presence => true
|
87
|
-
# end
|
88
|
-
#
|
89
|
-
# class EmployeeValidator < PersonValidator
|
90
|
-
# validates :employee_id, :presence => true
|
91
|
-
# end
|
92
|
-
#
|
93
|
-
# employee = Employee.new
|
94
|
-
# EmployeeValidator.validate!(employee) # => ["name is not present", "employee_id is not present"]
|
95
|
-
|
96
|
-
def inherited(descendant)
|
97
|
-
descendant.validate_with validators
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
# Initializes validator
|
102
|
-
#
|
103
|
-
# @param entity [Object] the entity instance to validate.
|
104
|
-
def initialize entity
|
105
|
-
@entity = entity
|
106
|
-
end
|
107
|
-
|
108
|
-
# Returns validating entity instance
|
109
|
-
# @return [Object]
|
110
|
-
def entity
|
111
|
-
@entity
|
112
|
-
end
|
113
|
-
|
114
|
-
# Returns errors object
|
115
|
-
#
|
116
|
-
# @return [Veto::Errors]
|
117
|
-
def errors
|
118
|
-
@errors ||= ::Veto::Errors.new
|
119
|
-
end
|
120
|
-
|
121
|
-
# Sets errors to nil.
|
122
|
-
def clear_errors
|
123
|
-
@errors = nil
|
124
|
-
end
|
125
|
-
|
126
|
-
# Returns boolean value representing the validaty of the entity
|
127
|
-
#
|
128
|
-
# @return [Boolean]
|
129
|
-
def valid?
|
130
|
-
execute
|
131
|
-
errors.empty?
|
132
|
-
end
|
133
|
-
|
134
|
-
# Raises exception if entity is invalid
|
135
|
-
#
|
136
|
-
# @example
|
137
|
-
# person = Person.new
|
138
|
-
# validator = PersonValidator.new(person)
|
139
|
-
# validator.validate! # => Veto::InvalidEntity, ["first name is not present", "..."]
|
140
|
-
#
|
141
|
-
# @raise [Veto::InvalidEntity] if the entity is invalid
|
142
|
-
def validate!
|
143
|
-
raise(::Veto::InvalidEntity, errors.full_messages) unless valid?
|
144
|
-
end
|
145
|
-
|
146
|
-
private
|
147
|
-
|
148
|
-
# Executes validation on the entity
|
149
|
-
def execute
|
150
|
-
clear_errors
|
151
|
-
run_validators
|
152
|
-
populate_entity_errors
|
153
|
-
end
|
154
|
-
|
155
|
-
# Runs each of the classes configured validators, passing the
|
156
|
-
# validator instance, entity, and errors object as arguments.
|
157
|
-
# Each validator will inspect the entity, run validations, and
|
158
|
-
# update the errors object according the the validation rules.
|
159
|
-
def run_validators
|
160
|
-
self.class.validators.each { |validator| validator.execute(self, entity, errors) }
|
161
|
-
end
|
162
|
-
|
163
|
-
# If the entity being validated has an errors accessor defined,
|
164
|
-
# assign the errors object to the entity.
|
165
|
-
def populate_entity_errors
|
166
|
-
if entity.respond_to?(:errors=)
|
167
|
-
entity.errors = errors
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
2
|
+
module Validator
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def with_options(*args, &block)
|
9
|
+
checker.with_options(*args, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def validates(*args)
|
13
|
+
checker.validates(*args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate(*args)
|
17
|
+
checker.validate(*args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_with(val)
|
21
|
+
@checker = val
|
22
|
+
end
|
23
|
+
|
24
|
+
def checker
|
25
|
+
@checker ||= build_checker
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def build_checker(children=[])
|
31
|
+
Checker.from_children(children)
|
32
|
+
end
|
33
|
+
|
34
|
+
def inherited(descendant)
|
35
|
+
descendant.check_with(build_checker(checker.children.dup))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def errors
|
40
|
+
@errors ||= ::Veto::Errors.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def valid?(entity)
|
44
|
+
validate(entity)
|
45
|
+
errors.empty?
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate!(entity)
|
49
|
+
raise(::Veto::InvalidEntity, errors) unless valid?(entity)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def clear_errors
|
55
|
+
@errors = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def validate(entity)
|
59
|
+
clear_errors
|
60
|
+
self.class.checker.call(CheckContextObject.new(entity, self, errors))
|
61
|
+
populate_entity_errors(entity)
|
62
|
+
end
|
63
|
+
|
64
|
+
def populate_entity_errors(entity)
|
65
|
+
if entity.respond_to?(:errors=)
|
66
|
+
entity.errors = errors
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
171
70
|
end
|
data/lib/veto/version.rb
CHANGED
data/lib/veto.rb
CHANGED
@@ -1,53 +1,94 @@
|
|
1
|
+
module Veto
|
2
|
+
# Provides access to the anonymous validator extension module
|
3
|
+
#
|
4
|
+
# @example
|
5
|
+
# class PersonValidator
|
6
|
+
# include Veto.validator
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# @return [Module] the object converted into the expected format.
|
10
|
+
def self.validator
|
11
|
+
mod = Module.new
|
12
|
+
mod.define_singleton_method :included do |base|
|
13
|
+
base.send(:include, ::Veto::Validator)
|
14
|
+
end
|
15
|
+
mod
|
16
|
+
end
|
17
|
+
|
18
|
+
# Provides access to the anonymous model extension module
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# class Person
|
22
|
+
# include Veto.model(PersonValidator)
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# @param validator [Class] the Veto validator class
|
26
|
+
# @return [Module] the object converted into the expected format.
|
27
|
+
def self.model validator
|
28
|
+
mod = Module.new
|
29
|
+
mod.define_singleton_method :included do |base|
|
30
|
+
base.send(:include, ::Veto::Model)
|
31
|
+
base.validates_with validator
|
32
|
+
end
|
33
|
+
mod
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.configure
|
37
|
+
yield(configuration)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.configuration
|
41
|
+
@configuration ||= Configuration.new
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# base
|
1
46
|
require 'veto/version'
|
2
|
-
require 'veto/
|
3
|
-
require 'veto/
|
47
|
+
require 'veto/exceptions'
|
48
|
+
require 'veto/errors'
|
4
49
|
require 'veto/configuration'
|
50
|
+
require 'veto/check_context_object'
|
5
51
|
|
6
|
-
|
52
|
+
# conditions
|
53
|
+
require 'veto/conditions/condition'
|
54
|
+
require 'veto/conditions/entity_eval_condition'
|
55
|
+
require 'veto/conditions/context_method_condition'
|
56
|
+
require 'veto/conditions/proc_condition'
|
57
|
+
require 'veto/conditions/primative_condition'
|
58
|
+
require 'veto/conditions/conditions'
|
59
|
+
require 'veto/conditions/if_conditions'
|
60
|
+
require 'veto/conditions/unless_conditions'
|
61
|
+
require 'veto/conditions/if_unless_conditions'
|
62
|
+
require 'veto/conditions/condition_factory'
|
63
|
+
|
64
|
+
# checks
|
65
|
+
require 'veto/checks/check'
|
66
|
+
require 'veto/checks/method_check'
|
67
|
+
require 'veto/checks/attribute_check'
|
68
|
+
require 'veto/checks/exact_length_check'
|
69
|
+
require 'veto/checks/format_check'
|
70
|
+
require 'veto/checks/greater_than_or_equal_to_check'
|
71
|
+
require 'veto/checks/greater_than_check'
|
72
|
+
require 'veto/checks/inclusion_check'
|
73
|
+
require 'veto/checks/integer_check'
|
74
|
+
require 'veto/checks/length_range_check'
|
75
|
+
require 'veto/checks/less_than_or_equal_to_check'
|
76
|
+
require 'veto/checks/less_than_check'
|
77
|
+
require 'veto/checks/max_length_check'
|
78
|
+
require 'veto/checks/min_length_check'
|
79
|
+
require 'veto/checks/not_null_check'
|
80
|
+
require 'veto/checks/numeric_check'
|
81
|
+
require 'veto/checks/presence_check'
|
82
|
+
require 'veto/checks/check_factory'
|
7
83
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
base.send(:include, ::Veto::Validator)
|
20
|
-
end
|
21
|
-
mod
|
22
|
-
end
|
23
|
-
|
24
|
-
# Provides access to the anonymous model extension module
|
25
|
-
#
|
26
|
-
# @example
|
27
|
-
# class Person
|
28
|
-
# include Veto.model(PersonValidator)
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
# @param validator [Class] the Veto validator class
|
32
|
-
# @return [Module] the object converted into the expected format.
|
33
|
-
def self.model validator
|
34
|
-
mod = Module.new
|
35
|
-
mod.define_singleton_method :included do |base|
|
36
|
-
base.send(:include, ::Veto::Model)
|
37
|
-
base.validates_with validator
|
38
|
-
end
|
39
|
-
mod
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.configure
|
43
|
-
yield(configuration)
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.configuration
|
47
|
-
@configuration ||= ::Veto::Configuration.new
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.configuration= val
|
51
|
-
@configuration = val
|
52
|
-
end
|
53
|
-
end
|
84
|
+
# validates
|
85
|
+
require 'veto/blocks/block'
|
86
|
+
require 'veto/blocks/conditional_block'
|
87
|
+
require 'veto/blocks/validate_block'
|
88
|
+
require 'veto/blocks/validates_block'
|
89
|
+
require 'veto/blocks/with_options_block'
|
90
|
+
require 'veto/blocks/checker'
|
91
|
+
|
92
|
+
# modules
|
93
|
+
require 'veto/validator'
|
94
|
+
require 'veto/model'
|