Class: Rackr::Router::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/rackr/router/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Route.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rackr/router/route.rb', line 12

def initialize(path, endpoint, befores: [], afters: [])
  @path = path
  @splitted_path = @path.split('/')
  @endpoint = endpoint
  @params = fetch_params
  @has_params = @params != []
  @befores = befores
  @has_befores = befores != []
  @afters = afters
  @has_afters = afters != []
  @path_regex = /\A#{path.gsub(/(:\w+)/, '([^/]+)')}\z/
end

Instance Attribute Details

#aftersObject (readonly)

Returns the value of attribute afters.



4
5
6
# File 'lib/rackr/router/route.rb', line 4

def afters
  @afters
end

#beforesObject (readonly)

Returns the value of attribute befores.



4
5
6
# File 'lib/rackr/router/route.rb', line 4

def befores
  @befores
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



4
5
6
# File 'lib/rackr/router/route.rb', line 4

def endpoint
  @endpoint
end

#has_aftersObject (readonly)

Returns the value of attribute has_afters.



4
5
6
# File 'lib/rackr/router/route.rb', line 4

def has_afters
  @has_afters
end

#has_beforesObject (readonly)

Returns the value of attribute has_befores.



4
5
6
# File 'lib/rackr/router/route.rb', line 4

def has_befores
  @has_befores
end

#has_paramsObject (readonly)

Returns the value of attribute has_params.



4
5
6
# File 'lib/rackr/router/route.rb', line 4

def has_params
  @has_params
end

#splitted_pathObject (readonly)

Returns the value of attribute splitted_path.



4
5
6
# File 'lib/rackr/router/route.rb', line 4

def splitted_path
  @splitted_path
end

Instance Method Details

#match?(env) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/rackr/router/route.rb', line 25

def match?(env)
  return env['PATH_INFO'].match?(@path_regex) if @has_params

  env['PATH_INFO'] == @path
end