Class: Sinatra::Chiro::Parameters::ParameterFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/chiro/parameters/parameter_factory.rb

Class Method Summary collapse

Class Method Details

.validator_from_type(options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sinatra/chiro/parameters/parameter_factory.rb', line 5

def self.validator_from_type(options)
  validator = case options[:type].to_s
                when 'String' then StringValidator
                when 'Fixnum' then FixnumValidator
                when 'Float' then FloatValidator
                when 'Date' then DateValidator
                when 'DateTime' then DateTimeValidator
                when 'Time' then TimeValidator
                when 'boolean' then BooleanValidator
                when '[String]' then ArrayValidator
                else
                  if options[:type].is_a? Regexp
                    RegexpValidator
                  end
              end
  validator.new(options)
end