Class: Rackr::Router::PathRoute
- Defined in:
- lib/rackr/router/path_route.rb
Overview
Path route is a route that has a path value that can be matched, and may have path params
Instance Attribute Summary collapse
-
#has_params ⇒ Object
readonly
Returns the value of attribute has_params.
-
#splitted_path ⇒ Object
readonly
Returns the value of attribute splitted_path.
Attributes inherited from Route
#afters, #befores, #endpoint, #has_afters, #has_befores
Instance Method Summary collapse
-
#initialize(path, endpoint, befores: [], afters: [], wildcard: false) ⇒ PathRoute
constructor
A new instance of PathRoute.
- #match?(path_info) ⇒ Boolean
Constructor Details
#initialize(path, endpoint, befores: [], afters: [], wildcard: false) ⇒ PathRoute
Returns a new instance of PathRoute.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rackr/router/path_route.rb', line 10 def initialize(path, endpoint, befores: [], afters: [], wildcard: false) super(endpoint, befores:, afters:) @path = path @splitted_path = @path.split('/') @params = fetch_params @has_params = @params != [] @path_regex = /\A#{path.gsub(/(:\w+)/, '([^/]+)')}\z/ @wildcard = wildcard end |
Instance Attribute Details
#has_params ⇒ Object (readonly)
Returns the value of attribute has_params.
7 8 9 |
# File 'lib/rackr/router/path_route.rb', line 7 def has_params @has_params end |
#splitted_path ⇒ Object (readonly)
Returns the value of attribute splitted_path.
7 8 9 |
# File 'lib/rackr/router/path_route.rb', line 7 def splitted_path @splitted_path end |
Instance Method Details
#match?(path_info) ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/rackr/router/path_route.rb', line 21 def match?(path_info) return path_info.match?(@path_regex) if @has_params return true if @wildcard path_info == @path end |