Class: Wayfarer::Routing::PathConsumer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/wayfarer/routing/path_consumer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Tracks path consumption during route matching.

Defined Under Namespace

Classes: ConsumptionState

Constant Summary collapse

INITIAL_OFFSET =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

nil
INITIAL_STATE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Initial valid state, before any path is consumed.

ConsumptionState.new(
  offset: INITIAL_OFFSET,
  params: Wayfarer::Routing::Route::EMPTY_PARAMS,
  valid?: true
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PathConsumer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of PathConsumer.



31
32
33
34
# File 'lib/wayfarer/routing/path_consumer.rb', line 31

def initialize(path)
  @path = File.join(File::SEPARATOR, path)
  @states = [INITIAL_STATE]
end

Instance Attribute Details

#pathString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns full path being consumed.



29
30
31
# File 'lib/wayfarer/routing/path_consumer.rb', line 29

def path
  @path
end

Instance Method Details

#current_stateConsumptionState

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The most recent consumption state.



46
47
48
# File 'lib/wayfarer/routing/path_consumer.rb', line 46

def current_state
  states.last
end

#popConsumptionState

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reverts to the previous state.



61
62
63
# File 'lib/wayfarer/routing/path_consumer.rb', line 61

def pop
  states.pop
end

#push(route) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Attempts to consume the path if the route has a Matchers::Path and pushes a new state as a result.



54
55
56
# File 'lib/wayfarer/routing/path_consumer.rb', line 54

def push(route)
  states.push(next_state(route))
end

#valid?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Whether the path was fully consumed or not consumed at all.



39
40
41
# File 'lib/wayfarer/routing/path_consumer.rb', line 39

def valid?
  current_state.valid? && consumed?
end