Class: Journey::Route

### Home Classes Methods

### In Files

- lib/journey/route.rb

### Parent

Object

### Methods

- ::new
- #ast
- #format
- #optional_parts
- #parts
- #required_defaults
- #required_keys
- #required_parts
- #score
- #segment_keys
- #segments

### 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::Route

### Attributes

app[R]
conditions[R]
constraints[R]
defaults[R]
ip[R]
name[R]
path[R]
precedence[RW]
verb[R]

### Public Class Methods

new(name, app, path, constraints, defaults = {}) click to toggle source

`path` is a path constraint. `constraints` is a hash of constraints to be applied to this route.

    # File lib/journey/route.rb, line 13
    def initialize name, app, path, constraints, defaults = {}
      constraints  = constraints.dup
      @name        = name
      @app         = app
      @path        = path
      @verb        = constraints[:request_method] || //
      @ip          = constraints.delete(:ip) || //

      @constraints = constraints
      @constraints.keep_if { |_,v| Regexp === v || String === v }
      @defaults    = defaults
      @required_defaults = nil
      @required_parts    = nil
      @parts             = nil
      @decorated_ast     = nil
      @precedence        = 0
    end

### Public Instance Methods

ast() click to toggle source

    # File lib/journey/route.rb, line 31
    def ast
      return @decorated_ast if @decorated_ast

      @decorated_ast = path.ast
      @decorated_ast.grep(Nodes::Terminal).each { |n| n.memo = self }
      @decorated_ast
    end

format(path_options) click to toggle source

    # File lib/journey/route.rb, line 69
    def format path_options
      (defaults.keys - required_parts).each do |key|
        path_options.delete key if defaults[key].to_s == path_options[key].to_s
      end

      formatter      = Visitors::Formatter.new(path_options)

      formatted_path = formatter.accept(path.spec)
      formatted_path.gsub(/\/\x00/, '')
    end

optional_parts() click to toggle source

    # File lib/journey/route.rb, line 80
    def optional_parts
      path.optional_names.map { |n| n.to_sym }
    end

parts() click to toggle source

    # File lib/journey/route.rb, line 64
    def parts
      @parts ||= segments.map { |n| n.to_sym }
    end

Also aliased as: segment_keys
required_defaults() click to toggle source

    # File lib/journey/route.rb, line 88
    def required_defaults
      @required_defaults ||= begin
        matches = parts
        @defaults.dup.delete_if { |k,_| matches.include? k }
      end
    end

required_keys() click to toggle source

    # File lib/journey/route.rb, line 50
    def required_keys
      path.required_names.map { |x| x.to_sym } + required_defaults.keys
    end

required_parts() click to toggle source

    # File lib/journey/route.rb, line 84
    def required_parts
      @required_parts ||= path.required_names.map { |n| n.to_sym }
    end

score(constraints) click to toggle source

    # File lib/journey/route.rb, line 54
    def score constraints
      required_keys = path.required_names
      supplied_keys = constraints.map { |k,v| v && k.to_s }.compact

      return -1 unless (required_keys - supplied_keys).empty?

      score = (supplied_keys & path.names).length
      score + (required_defaults.length * 2)
    end

segment_keys() click to toggle source
Alias for: parts
segments() click to toggle source

    # File lib/journey/route.rb, line 46
    def segments
      @path.names
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.