Class: Onboardable::List::Builder
- Inherits:
-
Object
- Object
- Onboardable::List::Builder
- 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
-
#current_step ⇒ Step
The current step in the building process, defaulting to the first added step.
Instance Method Summary collapse
-
#build(current_step_name = nil) ⇒ Base
Constructs a new List object from the steps added to the builder.
-
#create_step(name, data = {}) ⇒ Step
(also: #step)
Creates a new Step object and adds it to the builder.
-
#create_step_from(klass) ⇒ Step
(also: #step_from)
Converts a class to a Step object and adds it to the builder.
-
#initialize(options = {}) ⇒ Builder
constructor
Initializes a new instance of ListBuilder.
-
#steps ⇒ Hash
Stores the steps added to the builder.
Constructor Details
#initialize(options = {}) ⇒ Builder
Initializes a new instance of ListBuilder.
22 23 24 |
# File 'lib/onboardable/list/builder.rb', line 22 def initialize( = {}) self. = end |
Instance Attribute Details
#current_step ⇒ Step
Returns 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.
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), .except(STEP_KEY) ) end |
#create_step(name, data = {}) ⇒ Step Also known as: step
Creates a new Step object and adds it to the builder.
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.
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 |
#steps ⇒ Hash
Stores the steps added to the builder.
14 15 16 |
# File 'lib/onboardable/list/builder.rb', line 14 def steps [STEP_KEY] ||= {} end |