Sha256: 8621dab202d1420c7f7716aede416970ad02499a33f1a5efba71a3025d8260f6

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

class Usher
  class Route
    class Variable
      attr_reader :type, :name, :validator, :regex_matcher
      attr_accessor :look_ahead, :default_value, :look_ahead_priority
      
      def initialize(name, regex_matcher = nil, validator = nil)
        @name = name.to_s.to_sym
        @validator = validator
        @regex_matcher = regex_matcher
      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 #{@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.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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
usher-0.5.11 lib/usher/route/variable.rb
usher-0.5.10 lib/usher/route/variable.rb
usher-0.5.8 lib/usher/route/variable.rb