Class: Usher::Route::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/usher/route/variable.rb

Direct Known Subclasses

Glob, Single

Defined Under Namespace

Classes: Glob, Single

Constant Summary collapse

Greedy =
Class.new(Variable)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_valueObject

Returns the value of attribute default_value.



5
6
7
# File 'lib/usher/route/variable.rb', line 5

def default_value
  @default_value
end

#look_aheadObject

Returns the value of attribute look_ahead.



5
6
7
# File 'lib/usher/route/variable.rb', line 5

def look_ahead
  @look_ahead
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/usher/route/variable.rb', line 4

def name
  @name
end

#regex_matcherObject (readonly)

Returns the value of attribute regex_matcher.



4
5
6
# File 'lib/usher/route/variable.rb', line 4

def regex_matcher
  @regex_matcher
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/usher/route/variable.rb', line 4

def type
  @type
end

#validatorObject (readonly)

Returns the value of attribute validator.



4
5
6
# File 'lib/usher/route/variable.rb', line 4

def validator
  @validator
end

Instance Method Details

#==(o) ⇒ Object



27
28
29
# File 'lib/usher/route/variable.rb', line 27

def ==(o)
  o && (o.class == self.class && o.name == @name && o.validator == @validator)
end

#valid!(val) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/usher/route/variable.rb', line 14

def valid!(val)
  case @validator
  when Proc
    begin
      @validator.call(val)
    rescue Exception => e
      raise ValidationException.new("#{val} does not conform to #{@g}, root cause #{e.inspect}")
    end
  else
    @validator === val or raise(ValidationException.new("#{val} does not conform to #{@validator}, root cause #{e.inspect}"))
  end if @validator
end