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 =
Key used to store steps in the options hash.
: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.
27 28 29 |
# File 'lib/onboardable/list/builder.rb', line 27 def initialize( = {}) self. = end |
Instance Attribute Details
#current_step ⇒ Step
Returns The current step in the building process, defaulting to the first added step.
20 21 22 |
# File 'lib/onboardable/list/builder.rb', line 20 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.
54 55 56 57 58 59 60 |
# File 'lib/onboardable/list/builder.rb', line 54 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.
36 37 38 |
# File 'lib/onboardable/list/builder.rb', line 36 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.
45 46 47 |
# File 'lib/onboardable/list/builder.rb', line 45 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.
15 16 17 |
# File 'lib/onboardable/list/builder.rb', line 15 def steps [STEP_KEY] ||= {} end |