Class: Galago::Router::Path
- Inherits:
-
Object
- Object
- Galago::Router::Path
- Defined in:
- lib/galago/router/path.rb
Constant Summary collapse
- REPEATED_SLASH =
/\/{1,}/
- TRAILING_SLASH =
/\/$/
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ Path
constructor
A new instance of Path.
- #named_parameters ⇒ Object
- #params_from(env) ⇒ Object
- #recognizes?(request_path) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(path) ⇒ Path
Returns a new instance of Path.
15 16 17 |
# File 'lib/galago/router/path.rb', line 15 def initialize(path) @path = path.to_s end |
Class Method Details
.join(*paths) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/galago/router/path.rb', line 8 def self.join(*paths) path = "/#{paths.join('/')}" path = path.gsub(REPEATED_SLASH, '/') path = path.gsub(TRAILING_SLASH, '') path end |
Instance Method Details
#named_parameters ⇒ Object
23 24 25 |
# File 'lib/galago/router/path.rb', line 23 def named_parameters @path_parameters ||= @path.scan(/\:(\w+)/).flatten end |
#params_from(env) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/galago/router/path.rb', line 27 def params_from(env) request = Rack::Request.new(env) params = request.params if path_params = identify_params_in_path(request.path) params.merge(path_params) else params end end |
#recognizes?(request_path) ⇒ Boolean
19 20 21 |
# File 'lib/galago/router/path.rb', line 19 def recognizes?(request_path) request_path =~ regex end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/galago/router/path.rb', line 38 def to_s @path end |