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: [], wildcard: false) ⇒ Route

Returns a new instance of Route.



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

def initialize(path, endpoint, befores: [], afters: [], wildcard: false)
  @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/
  @wildcard = wildcard
end

Instance Attribute Details

#aftersObject (readonly)

Returns the value of attribute afters.



6
7
8
# File 'lib/rackr/router/route.rb', line 6

def afters
  @afters
end

#beforesObject (readonly)

Returns the value of attribute befores.



6
7
8
# File 'lib/rackr/router/route.rb', line 6

def befores
  @befores
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



6
7
8
# File 'lib/rackr/router/route.rb', line 6

def endpoint
  @endpoint
end

#has_aftersObject (readonly)

Returns the value of attribute has_afters.



6
7
8
# File 'lib/rackr/router/route.rb', line 6

def has_afters
  @has_afters
end

#has_beforesObject (readonly)

Returns the value of attribute has_befores.



6
7
8
# File 'lib/rackr/router/route.rb', line 6

def has_befores
  @has_befores
end

#has_paramsObject (readonly)

Returns the value of attribute has_params.



6
7
8
# File 'lib/rackr/router/route.rb', line 6

def has_params
  @has_params
end

#splitted_pathObject (readonly)

Returns the value of attribute splitted_path.



6
7
8
# File 'lib/rackr/router/route.rb', line 6

def splitted_path
  @splitted_path
end

Instance Method Details

#match?(path_info) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/rackr/router/route.rb', line 28

def match?(path_info)
  return path_info.match?(@path_regex) if @has_params
  return true if @wildcard

  path_info == @path
end