Class: LocoMotion::ComponentBuilder
- Inherits:
-
Object
- Object
- LocoMotion::ComponentBuilder
- Defined in:
- lib/loco_motion/component_builder.rb
Overview
Builder class for creating dynamic component subclasses with custom configurations. This class encapsulates the complex metaprogramming logic needed to create customized component instances without defining new classes.
Instance Attribute Summary collapse
-
#base_class ⇒ Object
readonly
Returns the value of attribute base_class.
-
#build_block ⇒ Object
readonly
Returns the value of attribute build_block.
-
#build_kws ⇒ Object
readonly
Returns the value of attribute build_kws.
Instance Method Summary collapse
-
#build ⇒ Class
Build the customized component subclass.
-
#initialize(base_class, build_kws = {}, &build_block) ⇒ ComponentBuilder
constructor
Initialize a new component builder.
Constructor Details
#initialize(base_class, build_kws = {}, &build_block) ⇒ ComponentBuilder
Initialize a new component builder.
19 20 21 22 23 24 |
# File 'lib/loco_motion/component_builder.rb', line 19 def initialize(base_class, build_kws = {}, &build_block) @base_class = base_class @build_kws = build_kws @build_block = build_block @build_counter = base_class.instance_variable_get(:@build_counter) || 0 end |
Instance Attribute Details
#base_class ⇒ Object (readonly)
Returns the value of attribute base_class.
10 11 12 |
# File 'lib/loco_motion/component_builder.rb', line 10 def base_class @base_class end |
#build_block ⇒ Object (readonly)
Returns the value of attribute build_block.
10 11 12 |
# File 'lib/loco_motion/component_builder.rb', line 10 def build_block @build_block end |
#build_kws ⇒ Object (readonly)
Returns the value of attribute build_kws.
10 11 12 |
# File 'lib/loco_motion/component_builder.rb', line 10 def build_kws @build_kws end |
Instance Method Details
#build ⇒ Class
Build the customized component subclass.
31 32 33 34 35 36 37 38 39 |
# File 'lib/loco_motion/component_builder.rb', line 31 def build klass = create_subclass setup_component_name(klass) setup_sidecar_files(klass) override_initialize(klass) apply_customizations(klass) increment_counter klass end |