Class: Validate::Scope
- Inherits:
-
Object
- Object
- Validate::Scope
- Defined in:
- lib/validate/scope.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Scope
constructor
A new instance of Scope.
- #register_validator(name, validator) ⇒ Object
- #validator(name) ⇒ Object
- #validator?(name) ⇒ Boolean
Constructor Details
#initialize ⇒ Scope
Returns a new instance of Scope.
10 11 12 13 |
# File 'lib/validate/scope.rb', line 10 def initialize @constraints = {} @validators = {} end |
Class Method Details
Instance Method Details
#register_validator(name, validator) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/validate/scope.rb', line 15 def register_validator(name, validator) if @validators.include?(name) raise Error::ArgumentError, "duplicate validator :#{name}" end @validators[name] = validator end |
#validator(name) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/validate/scope.rb', line 28 def validator(name) validator_name.assert(name, message: "invalid validator #{name.inspect}", error_class: KeyError) @validators.fetch(name) { name.validator } end |
#validator?(name) ⇒ Boolean
24 25 26 |
# File 'lib/validate/scope.rb', line 24 def validator?(name) @validators.include?(name) end |