Class: Rack::HttpRouter::Router::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-http_router/router/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, endpoint, befores = []) ⇒ Route

Returns a new instance of Route.



9
10
11
12
13
14
15
16
17
# File 'lib/rack-http_router/router/route.rb', line 9

def initialize(path, endpoint, befores = [])
  @path = path
  @splitted_path = @path.split('/')
  @endpoint = endpoint
  @params = fetch_params
  @has_params = @params != []
  @befores = befores
  @has_befores = befores != []
end

Instance Attribute Details

#beforesObject (readonly)

Returns the value of attribute befores.



7
8
9
# File 'lib/rack-http_router/router/route.rb', line 7

def befores
  @befores
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



7
8
9
# File 'lib/rack-http_router/router/route.rb', line 7

def endpoint
  @endpoint
end

#has_beforesObject (readonly)

Returns the value of attribute has_befores.



7
8
9
# File 'lib/rack-http_router/router/route.rb', line 7

def has_befores
  @has_befores
end

#has_paramsObject (readonly)

Returns the value of attribute has_params.



7
8
9
# File 'lib/rack-http_router/router/route.rb', line 7

def has_params
  @has_params
end

#splitted_pathObject (readonly)

Returns the value of attribute splitted_path.



7
8
9
# File 'lib/rack-http_router/router/route.rb', line 7

def splitted_path
  @splitted_path
end

Instance Method Details

#match?(env) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/rack-http_router/router/route.rb', line 19

def match?(env)
  return match_with_params?(env) if @has_params

  env['REQUEST_PATH'] == @path
end