Class: Escort::Validator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ Validator

Returns a new instance of Validator.



11
12
13
# File 'lib/escort/validator.rb', line 11

def initialize(parser)
  @parser = parser
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



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

def parser
  @parser
end

Class Method Details

.for(parser) ⇒ Object



4
5
6
# File 'lib/escort/validator.rb', line 4

def for(parser)
  self.new(parser)
end

Instance Method Details

#validate(options, validations) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/escort/validator.rb', line 15

def validate(options, validations)
  validations.each do |option, validations_array|
    if option_exists?(option)
      validate_option(option, options, validations_array)
    else
      raise Escort::ClientError.new("Unable to create validation for '#{option}' as no such option was defined, maybe you misspelled it")
    end
  end
  options
end