Module: HashValidator
- Defined in:
- lib/hash_validator.rb,
lib/hash_validator/version.rb,
lib/hash_validator/validators.rb,
lib/hash_validator/validations.rb,
lib/hash_validator/validators/many_validator.rb,
lib/hash_validator/validators/multiple_validator.rb,
lib/hash_validator/validators/optional_validator.rb
Defined Under Namespace
Modules: Validations, Validator
Classes: Base
Constant Summary
collapse
- VERSION =
'1.1.1'
- @@validators =
[]
Class Method Summary
collapse
Class Method Details
.append_validator(validator) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/hash_validator/validators.rb', line 5
def self.append_validator(validator)
unless validator.is_a?(HashValidator::Validator::Base)
raise StandardError.new('validators need to inherit from HashValidator::Validator::Base')
end
if @@validators.detect { |v| v.name == validator.name }
raise StandardError.new('validators need to have unique names')
end
@@validators << validator
end
|
.many(validation) ⇒ Object
10
11
12
|
# File 'lib/hash_validator.rb', line 10
def self.many(validation)
Validations::Many.new(validation)
end
|
.multiple(*validations) ⇒ Object
14
15
16
|
# File 'lib/hash_validator.rb', line 14
def self.multiple(*validations)
Validations::Multiple.new(validations)
end
|
.optional(validation) ⇒ Object
6
7
8
|
# File 'lib/hash_validator.rb', line 6
def self.optional(validation)
Validations::Optional.new(validation)
end
|
.validate(*args) ⇒ Object
2
3
4
|
# File 'lib/hash_validator.rb', line 2
def self.validate(*args)
Base.validate(*args)
end
|
.validator_for(rhs) ⇒ Object
17
18
19
|
# File 'lib/hash_validator/validators.rb', line 17
def self.validator_for(rhs)
@@validators.detect { |v| v.should_validate?(rhs) } || raise(StandardError.new("Could not find valid validator for: #{rhs}"))
end
|