Class: Orbit::Routing::Path
- Inherits:
-
Object
- Object
- Orbit::Routing::Path
- Defined in:
- lib/orbit/routing/path.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
Instance Method Summary collapse
- #compile ⇒ Object
- #get_params(path) ⇒ Object
-
#initialize(path) ⇒ Path
constructor
A new instance of Path.
Constructor Details
#initialize(path) ⇒ Path
Returns a new instance of Path.
6 7 8 9 |
# File 'lib/orbit/routing/path.rb', line 6 def initialize(path) @name = path @regex, @keys = compile end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/orbit/routing/path.rb', line 4 def name @name end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
4 5 6 |
# File 'lib/orbit/routing/path.rb', line 4 def regex @regex end |
Instance Method Details
#compile ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/orbit/routing/path.rb', line 22 def compile return compile_string if name.respond_to? :to_str if is_hash? [name, name.keys] elsif is_object? [name, name.names] elsif name.respond_to? :match [name, []] else raise TypeError, name end end |
#get_params(path) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/orbit/routing/path.rb', line 11 def get_params(path) matches = regex.match(path) {}.tap do |params| keys.each_with_index do |key, index| match_index = index + 1 params[key.to_sym] = (matches[match_index]) if matches && matches.size > match_index end end end |