Class: Avalon::Validator
- Inherits:
-
Object
- Object
- Avalon::Validator
- Defined in:
- lib/avalon/validator.rb
Instance Method Summary collapse
-
#initialize(target, *patterns, &block) ⇒ Validator
constructor
A new instance of Validator.
- #invalid? ⇒ Boolean
- #valid? ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(target, *patterns, &block) ⇒ Validator
Returns a new instance of Validator.
3 4 5 6 7 |
# File 'lib/avalon/validator.rb', line 3 def initialize(target, *patterns, &block) @target = target @patterns = patterns @patterns << block if block_given? end |
Instance Method Details
#invalid? ⇒ Boolean
18 19 20 |
# File 'lib/avalon/validator.rb', line 18 def invalid? !valid? end |
#valid? ⇒ Boolean
14 15 16 |
# File 'lib/avalon/validator.rb', line 14 def valid? @patterns.any? {|pattern| check(pattern) } end |
#validate ⇒ Object
9 10 11 12 |
# File 'lib/avalon/validator.rb', line 9 def validate raise_error if invalid? true end |