class Journey::Routes - journey-1.0.4 Documentation

# class Journey::Routes

The Routing table. Contains all routes for a system. Routes can be added to the table by calling #add_route

### Attributes

named_routes[R]
routes[R]

### Public Class Methods

new() click to toggle source

    # File lib/journey/routes.rb, line 10
    def initialize
      @routes             = []
      @named_routes       = {}
      @ast                = nil
      @partitioned_routes = nil
      @simulator          = nil
    end

### Public Instance Methods

add_route(app, path, conditions, defaults, name = nil) click to toggle source

Add a route to the routing table.

    # File lib/journey/routes.rb, line 58
    def add_route app, path, conditions, defaults, name = nil
      route = Route.new(name, app, path, conditions, defaults)

      route.precedence = routes.length
      routes << route
      named_routes[name] = route if name
      clear_cache!
      route
    end

ast() click to toggle source

    # File lib/journey/routes.rb, line 41
    def ast
      return @ast if @ast
      return if partitioned_routes.first.empty?

      asts = partitioned_routes.first.map { |r| r.ast }
      @ast = Nodes::Or.new(asts)
    end

clear() click to toggle source

    # File lib/journey/routes.rb, line 31
    def clear
      routes.clear
    end

each(&block) click to toggle source

    # File lib/journey/routes.rb, line 27
    def each(&block)
      routes.each(&block)
    end

last() click to toggle source

    # File lib/journey/routes.rb, line 23
    def last
      @routes.last
    end

length() click to toggle source

    # File lib/journey/routes.rb, line 18
    def length
      @routes.length
    end

Also aliased as: size
partitioned_routes() click to toggle source

    # File lib/journey/routes.rb, line 35
    def partitioned_routes
      @partitioned_routes ||= routes.partition { |r|
        r.path.anchored && r.ast.grep(Nodes::Symbol).all? { |n| n.default_regexp?  }
      }
    end

simulator() click to toggle source

    # File lib/journey/routes.rb, line 49
    def simulator
      return @simulator if @simulator

      gtg = GTG::Builder.new(ast).transition_table
      @simulator = GTG::Simulator.new gtg
    end

size()
Alias for: length