Module: Onboardable::List::Navigation

Included in:
Base
Defined in:
lib/onboardable/list/navigation.rb

Overview

The Navigation module provides methods for navigating through the steps of the onboarding process.

Instance Method Summary collapse

Instance Method Details

#current_step?(step) ⇒ Boolean

Checks if the specified step is the current step in the onboarding process.

Parameters:

  • step (Step)

    The step to check.

Returns:

  • (Boolean)

    True if the specified step is the current step, false otherwise.



80
81
82
# File 'lib/onboardable/list/navigation.rb', line 80

def current_step?(step)
  current_step == step
end

#first_stepStep

Retrieves the first step in the onboarding process.

Returns:

  • (Step)

    The first step in the list.



72
73
74
# File 'lib/onboardable/list/navigation.rb', line 72

def first_step
  steps.fetch(0)
end

#first_step?(step = current_step) ⇒ Boolean

Checks if the specified step is the first step in the onboarding process.

Parameters:

  • step (Step) (defaults to: current_step)

    The step to check (defaults to the current step if not specified).

Returns:

  • (Boolean)

    True if the specified step is the first step, false otherwise.



57
58
59
# File 'lib/onboardable/list/navigation.rb', line 57

def first_step?(step = current_step)
  first_step == step
end

#last_stepStep

Retrieves the last step in the onboarding process.

Returns:

  • (Step)

    The last step in the list.



87
88
89
# File 'lib/onboardable/list/navigation.rb', line 87

def last_step
  steps.fetch(-1)
end

#last_step?(step = current_step) ⇒ Boolean

Checks if the specified step is the last step in the onboarding process.

Parameters:

  • step (Step) (defaults to: current_step)

    The step to check (defaults to the current step if not specified).

Returns:

  • (Boolean)

    True if the specified step is the last step, false otherwise.



65
66
67
# File 'lib/onboardable/list/navigation.rb', line 65

def last_step?(step = current_step)
  last_step == step
end

#next_stepStep?

Returns the next step in the onboarding process.

Returns:

  • (Step, nil)

    The next step in the list or nil if the current step is the last one.



10
11
12
13
# File 'lib/onboardable/list/navigation.rb', line 10

def next_step
  current_index = step_index(current_step)
  steps[current_index.next]
end

#next_step!Step

Moves the current step pointer to the next step in the onboarding process.

Returns:

  • (Step)

    The next step in the list.



26
27
28
# File 'lib/onboardable/list/navigation.rb', line 26

def next_step!
  self.current_step = next_step || last_step_error!
end

#next_step?(step) ⇒ Boolean

Checks if the specified step is the next step in the onboarding process.

Parameters:

  • step (Step)

    The step to check.

Returns:

  • (Boolean)

    True if the specified step is the next step, false otherwise.



19
20
21
# File 'lib/onboardable/list/navigation.rb', line 19

def next_step?(step)
  next_step == step
end

#prev_stepStep?

Returns the previous step in the onboarding process.

Returns:

  • (Step, nil)

    The previous step in the list or nil if the current step is the first one.



33
34
35
36
# File 'lib/onboardable/list/navigation.rb', line 33

def prev_step
  current_index = step_index(current_step)
  current_index.positive? ? steps[current_index.pred] : nil
end

#prev_step!Step

Moves the current step pointer to the previous step in the onboarding process.

Returns:

  • (Step)

    The previous step in the list.



49
50
51
# File 'lib/onboardable/list/navigation.rb', line 49

def prev_step!
  self.current_step = prev_step || first_step_error!
end

#prev_step?(step) ⇒ Boolean

Checks if the specified step is the previous step in the onboarding process.

Parameters:

  • step (Step)

    The step to check.

Returns:

  • (Boolean)

    True if the specified step is the previous step, false otherwise.



42
43
44
# File 'lib/onboardable/list/navigation.rb', line 42

def prev_step?(step)
  prev_step == step
end