Class: Rackr::Router::Route
- Inherits:
-
Object
- Object
- Rackr::Router::Route
- Defined in:
- lib/rackr/router/route.rb
Instance Attribute Summary collapse
-
#afters ⇒ Object
readonly
Returns the value of attribute afters.
-
#befores ⇒ Object
readonly
Returns the value of attribute befores.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#has_afters ⇒ Object
readonly
Returns the value of attribute has_afters.
-
#has_befores ⇒ Object
readonly
Returns the value of attribute has_befores.
-
#has_params ⇒ Object
readonly
Returns the value of attribute has_params.
-
#splitted_path ⇒ Object
readonly
Returns the value of attribute splitted_path.
Instance Method Summary collapse
-
#initialize(path, endpoint, befores: [], afters: []) ⇒ Route
constructor
A new instance of Route.
- #match?(env) ⇒ Boolean
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
#afters ⇒ Object (readonly)
Returns the value of attribute afters.
4 5 6 |
# File 'lib/rackr/router/route.rb', line 4 def afters @afters end |
#befores ⇒ Object (readonly)
Returns the value of attribute befores.
4 5 6 |
# File 'lib/rackr/router/route.rb', line 4 def befores @befores end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
4 5 6 |
# File 'lib/rackr/router/route.rb', line 4 def endpoint @endpoint end |
#has_afters ⇒ Object (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_befores ⇒ Object (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_params ⇒ Object (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_path ⇒ Object (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
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 |