Class: Onboardable::List::Builder

Inherits:
Object
  • Object
show all
Includes:
Utils::Warnings
Defined in:
lib/onboardable/list/builder.rb

Overview

The Builder class constructs and manages an onboarding step list, adding steps and building the final list.

Constant Summary collapse

STEP_KEY =
:steps

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Builder

Initializes a new instance of ListBuilder.



22
23
24
# File 'lib/onboardable/list/builder.rb', line 22

def initialize(options = {})
  self.options = options
end

Instance Attribute Details

#current_stepStep

Returns The current step in the building process, defaulting to the first added step.

Returns:

  • (Step)

    The current step in the building process, defaulting to the first added step.



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

def current_step
  @current_step
end

Instance Method Details

#build(current_step_name = nil) ⇒ Base

Constructs a new List object from the steps added to the builder.

Parameters:

  • current_step_name (String, nil) (defaults to: nil)

    The name of the current step.

Returns:

  • (Base)

    A new List object initialized with the steps and the specified current step.



49
50
51
52
53
54
55
# File 'lib/onboardable/list/builder.rb', line 49

def build(current_step_name = nil)
  Base.new(
    convert_to_steps!,
    convert_to_step!(current_step_name || current_step.name),
    options.except(STEP_KEY)
  )
end

#create_step(name, data = {}) ⇒ Step Also known as: step

Creates a new Step object and adds it to the builder.

Parameters:

  • name (String)

    The name of the step.

  • data (Hash) (defaults to: {})

    The data associated with the step.

Returns:

  • (Step)

    The created step.



31
32
33
# File 'lib/onboardable/list/builder.rb', line 31

def create_step(name, data = {})
  Step.new(name, data).tap { |step| add_step(step) }
end

#create_step_from(klass) ⇒ Step Also known as: step_from

Converts a class to a Step object and adds it to the builder.

Parameters:

  • klass (Class)

    The class to be converted to a step.

Returns:

  • (Step)

    The converted step.



40
41
42
# File 'lib/onboardable/list/builder.rb', line 40

def create_step_from(klass)
  (Step.try_convert(klass) || undefined_method_error!(klass)).tap { |step| add_step(step) }
end

#stepsHash

Stores the steps added to the builder.

Returns:

  • (Hash)

    A hash of steps added to the builder.



14
15
16
# File 'lib/onboardable/list/builder.rb', line 14

def steps
  options[STEP_KEY] ||= {}
end