Class: Plumbing::Provider::Router::DynamicRoute
- Defined in:
- lib/plumbing/provider/router.rb
Instance Method Summary collapse
- #_generate_params ⇒ Object
- #_generate_statics ⇒ Object
- #_match_for?(segments) ⇒ Boolean
- #_size_match_for?(segments) ⇒ Boolean
- #_static_match_for?(segments) ⇒ Boolean
- #dynamic? ⇒ Boolean
- #matches_for(path) ⇒ Object
- #static? ⇒ Boolean
Methods inherited from Route
Instance Method Details
#_generate_params ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/plumbing/provider/router.rb', line 30 def _generate_params @path.split("/") .map .with_index { |segment, position| [position, segment] } .select { |(position, segment)| segment.start_with? ":" } .map { |(position, segment)| [position, segment.delete_prefix(":").to_sym] } .to_h end |
#_generate_statics ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/plumbing/provider/router.rb', line 39 def _generate_statics @path.split("/") .map .with_index { |segment, position| [position, segment] } .reject { |(position, segment)| segment.start_with? ":" } .to_h end |
#_match_for?(segments) ⇒ Boolean
47 |
# File 'lib/plumbing/provider/router.rb', line 47 def _match_for?(segments) = _size_match_for?(segments) && _static_match_for?(segments) |
#_size_match_for?(segments) ⇒ Boolean
48 |
# File 'lib/plumbing/provider/router.rb', line 48 def _size_match_for?(segments) = (segments.size == @segments.size) |
#_static_match_for?(segments) ⇒ Boolean
50 |
# File 'lib/plumbing/provider/router.rb', line 50 def _static_match_for?(segments) = @statics.all? { |position, segment| segments[position] == segment } |
#dynamic? ⇒ Boolean
23 |
# File 'lib/plumbing/provider/router.rb', line 23 def dynamic? = true |
#matches_for(path) ⇒ Object
25 26 27 28 |
# File 'lib/plumbing/provider/router.rb', line 25 def matches_for path segments = path.split("/") _match_for?(segments) ? @statics.size : 0 end |
#static? ⇒ Boolean
22 |
# File 'lib/plumbing/provider/router.rb', line 22 def static? = false |