lib/usher/route/variable.rb in usher-0.4.8 vs lib/usher/route/variable.rb in usher-0.5.1

- old
+ new

@@ -1,37 +1,48 @@ class Usher class Route class Variable attr_reader :type, :name, :validator, :regex_matcher - attr_accessor :look_ahead, :globs_capture_separators, :default_value + attr_accessor :look_ahead, :default_value - def initialize(type, name, validator = nil, regex_matcher = nil, globs_capture_separators = false) - @type = type - @name = :"#{name}" + def initialize(name, regex_matcher = nil, validator = nil) + @name = name.to_s.to_sym @validator = validator @regex_matcher = regex_matcher - @globs_capture_separators = globs_capture_separators end - - def to_s - "#{type}#{name}" - end + private :initialize def valid!(val) case @validator when Proc begin @validator.call(val) rescue Exception => e - raise ValidationException.new("#{val} does not conform to #{@validator}, root cause #{e.inspect}") + 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 def ==(o) - o && (o.type == @type && o.name == @name && o.validator == @validator) + o && (o.class == self.class && o.name == @name && o.validator == @validator) end + + class Single < Variable + def to_s + ":#{name}" + end + end + + class Glob < Variable + def to_s + "*#{name}" + end + end + + Greedy = Class.new(Variable) + end + end end \ No newline at end of file