Sha256: 24a578422cfb020892cc5862a1232668450c5a5264dd9c654d266dc81e888466

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

$:.unshift File.dirname(__FILE__)

require 'route/path'
require 'route/splitter'
require 'route/variable'
require 'route/request_method'

class Usher
  class Route
    attr_reader :paths, :original_path, :requirements, :conditions, :params, :primary_path
    
    def initialize(original_path, router, options = {})
      @original_path = original_path
      @router = router
      @requirements = options.delete(:requirements)
      @conditions = options.delete(:conditions)
      @transformers = options.delete(:transformers)
      @paths = Splitter.new(@original_path, @requirements, @transformers).paths.collect {|path| Path.new(self, path)}
      @primary_path = @paths.first
    end
    
    
    # Sets +options+ on a route
    #   
    #   Request = Struct.new(:path)
    #   set = Usher.new
    #   route = set.add_route('/test')
    #   route.to(:controller => 'testing', :action => 'index')
    #   set.recognize(Request.new('/test')).first.params => {:controller => 'testing', :action => 'index'}
    def to(options)
      @params = options
      self
    end

    def name(name)
      @router.name(name, self)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
joshbuddy-usher-0.2.1 lib/usher/route.rb