Class: Lennarb::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/lennarb/routes.rb

Overview

Routes class for managing application routes

Instance Method Summary collapse

Constructor Details

#initializeRoutes

Initialize a new Routes instance



8
9
10
11
# File 'lib/lennarb/routes.rb', line 8

def initialize
  @store = RouteNode.new
  @frozen = false
end

Instance Method Details

#freezeself

Freeze the routes to prevent further modification

Returns:

  • (self)

    The frozen routes



41
42
43
44
45
# File 'lib/lennarb/routes.rb', line 41

def freeze
  @frozen = true
  @store.freeze
  self
end

#frozen?Boolean

Check if the routes are frozen

Returns:

  • (Boolean)

    True if frozen



50
51
52
# File 'lib/lennarb/routes.rb', line 50

def frozen?
  @frozen
end

#match_route(parts, http_method) ⇒ Array(Proc, Hash)?

Match a route with the given path parts and HTTP method

Parameters:

  • parts (Array<String>)

    Path parts

  • http_method (Symbol)

    HTTP method

Returns:

  • (Array(Proc, Hash), nil)

    Route handler and params, or nil if no match



34
35
36
# File 'lib/lennarb/routes.rb', line 34

def match_route(parts, http_method)
  @store.match_route(parts, http_method)
end

#root(&block) ⇒ void

This method returns an undefined value.

Define the root route (GET /)

Parameters:

  • block (Proc)

    Block to execute when route matches



25
26
27
# File 'lib/lennarb/routes.rb', line 25

def root(&block)
  get("/", &block)
end