lib/usher/route/variable.rb in joshbuddy-usher-0.4.3 vs lib/usher/route/variable.rb in joshbuddy-usher-0.4.5

- old
+ new

@@ -1,10 +1,10 @@ class Usher class Route class Variable attr_reader :type, :name, :validator, :regex_matcher - attr_accessor :look_ahead, :globs_capture_separators + attr_accessor :look_ahead, :globs_capture_separators, :default_value def initialize(type, name, validator = nil, regex_matcher = nil, globs_capture_separators = false) @type = type @name = :"#{name}" @validator = validator @@ -17,17 +17,19 @@ end def valid!(val) case @validator when Proc - @validator.call(val) + begin + @validator.call(val) + rescue Exception => e + raise ValidationException.new("#{val} does not conform to #{@validator}, root cause #{e.inspect}") + end else - @validator === val or raise + @validator === val or raise(ValidationException.new("#{val} does not conform to #{@validator}, root cause #{e.inspect}")) end if @validator - rescue Exception => e - raise ValidationException.new("#{val} does not conform to #{@validator}, root cause #{e.inspect}") end - + def ==(o) o && (o.type == @type && o.name == @name && o.validator == @validator) end end end \ No newline at end of file