Class: Plumbing::Provider::Router::DynamicRoute

Inherits:
Route
  • Object
show all
Defined in:
lib/plumbing/provider/router.rb

Instance Method Summary collapse

Methods inherited from Route

#wildcard?

Instance Method Details

#_generate_paramsObject



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_staticsObject



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

Returns:

  • (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

Returns:

  • (Boolean)


48
# File 'lib/plumbing/provider/router.rb', line 48

def _size_match_for?(segments) = (segments.size == @segments.size)

#_static_match_for?(segments) ⇒ Boolean

Returns:

  • (Boolean)


50
# File 'lib/plumbing/provider/router.rb', line 50

def _static_match_for?(segments) = @statics.all? { |position, segment| segments[position] == segment }

#dynamic?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


22
# File 'lib/plumbing/provider/router.rb', line 22

def static? = false