Class: Avalon::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/avalon/validator.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


18
19
20
# File 'lib/avalon/validator.rb', line 18

def invalid?
  !valid?
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/avalon/validator.rb', line 14

def valid?
  @patterns.any? {|pattern| check(pattern) }
end

#validateObject



9
10
11
12
# File 'lib/avalon/validator.rb', line 9

def validate
  raise_error if invalid?
  true
end