Class: Journey::Router

### Home Classes Methods

### In Files

- lib/journey/router.rb
- lib/journey/router/strexp.rb
- lib/journey/router/utils.rb

### Parent

Object

### Namespace

- CLASS Journey::Router::RoutingError
- CLASS Journey::Router::Strexp
- CLASS Journey::Router::Utils

### Methods

- ::new
- #call
- #recognize
- #visualizer

### Files

- CHANGELOG.rdoc
- Manifest.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Journey
- Journey::Formatter
- Journey::GTG
- Journey::GTG::Builder
- Journey::GTG::MatchData
- Journey::GTG::Simulator
- Journey::GTG::TransitionTable
- Journey::NFA
- Journey::NFA::Builder
- Journey::NFA::MatchData
- Journey::NFA::Simulator
- Journey::NFA::TransitionTable
- Journey::NFA::Visitor
- Journey::Nodes
- Journey::Nodes::Binary
- Journey::Nodes::Cat
- Journey::Nodes::Dummy
- Journey::Nodes::Group
- Journey::Nodes::Literal
- Journey::Nodes::Or
- Journey::Nodes::Star
- Journey::Nodes::Symbol
- Journey::Nodes::Terminal
- Journey::Nodes::Unary
- Journey::Parser
- Journey::Path
- Journey::Path::Pattern
- Journey::Path::Pattern::MatchData
- Journey::Route
- Journey::Router
- Journey::Router::RoutingError
- Journey::Router::Strexp
- Journey::Router::Utils
- Journey::Router::Utils::UriEscape
- Journey::Routes
- Journey::Scanner
- Rack

No matching classes.

# Journey::Router

### Constants

VERSION

### Attributes

formatter[R]
request_class[R]
routes[RW]

### Public Class Methods

new(routes, options) click to toggle source

    # File lib/journey/router.rb, line 46
    def initialize routes, options
      @options       = options
      @params_key    = options[:parameters_key]
      @request_class = options[:request_class] || NullReq
      @routes        = routes
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/journey/router.rb, line 53
    def call env
      env['PATH_INFO'] = Utils.normalize_path env['PATH_INFO']

      find_routes(env).each do |match, parameters, route|
        script_name, path_info, set_params = env.values_at('SCRIPT_NAME',
                                                           'PATH_INFO',
                                                           @params_key)

        unless route.path.anchored
          env['SCRIPT_NAME'] = (script_name.to_s + match.to_s).chomp('/')
          env['PATH_INFO']   = Utils.normalize_path(match.post_match)
        end

        env[@params_key] = (set_params || {}).merge parameters

        status, headers, body = route.app.call(env)

        if 'pass' == headers['X-Cascade']
          env['SCRIPT_NAME'] = script_name
          env['PATH_INFO']   = path_info
          env[@params_key]   = set_params
          next
        end

        return [status, headers, body]
      end

      return [404, {'X-Cascade' => 'pass'}, ['Not Found']]
    end

recognize(req) click to toggle source

    # File lib/journey/router.rb, line 83
    def recognize req
      find_routes(req.env).each do |match, parameters, route|
        unless route.path.anchored
          req.env['SCRIPT_NAME'] = match.to_s
          req.env['PATH_INFO']   = match.post_match.sub(/^([^\/])/, '/\1')
        end

        yield(route, nil, parameters)
      end
    end

visualizer() click to toggle source

    # File lib/journey/router.rb, line 94
    def visualizer
      tt     = GTG::Builder.new(ast).transition_table
      groups = partitioned_routes.first.map(&:ast).group_by { |a| a.to_s }
      asts   = groups.values.map { |v| v.first }
      tt.visualizer asts
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.