Class: Rack::Way::Router::Route

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, endpoint) ⇒ Route

Returns a new instance of Route.



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

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

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
end

#has_paramsObject (readonly)

Returns the value of attribute has_params.



7
8
9
# File 'lib/rack-way/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-way/router/route.rb', line 7

def splitted_path
  @splitted_path
end

Instance Method Details

#match?(env) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/rack-way/router/route.rb', line 17

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

  env['REQUEST_PATH'] == @path
end