Class: Axn::Mountable::Helpers::ClassBuilder
- Inherits:
-
Object
- Object
- Axn::Mountable::Helpers::ClassBuilder
- Defined in:
- lib/axn/mountable/helpers/class_builder.rb
Overview
Handles building and configuring Axn action classes for mounting
Instance Method Summary collapse
- #build_and_configure_action_class(target, name, namespace) ⇒ Object
- #generate_constant_name(name) ⇒ Object
-
#initialize(descriptor) ⇒ ClassBuilder
constructor
A new instance of ClassBuilder.
- #mount(target, name) ⇒ Object
Constructor Details
#initialize(descriptor) ⇒ ClassBuilder
Returns a new instance of ClassBuilder.
11 12 13 |
# File 'lib/axn/mountable/helpers/class_builder.rb', line 11 def initialize(descriptor) @descriptor = descriptor end |
Instance Method Details
#build_and_configure_action_class(target, name, namespace) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/axn/mountable/helpers/class_builder.rb', line 26 def build_and_configure_action_class(target, name, namespace) # Mark target as having an action class being created to prevent recursion # This is necessary because create_superclass_for_inherit_mode may create # classes that inherit from target, triggering the inherited callback target.instance_variable_set(:@_axn_creating_action_class_for, target) begin # Pass target through to Factory.build so it can mark the superclass # The superclass flag is checked by the inherited callback in mountable.rb mounted_axn = build_action_class(target, _creating_action_class_for: target) configure_class_name_and_constant(mounted_axn, name, namespace, target) configure_axn_mounted_to(mounted_axn, target) mounted_axn ensure target.instance_variable_set(:@_axn_creating_action_class_for, nil) end end |
#generate_constant_name(name) ⇒ Object
22 23 24 |
# File 'lib/axn/mountable/helpers/class_builder.rb', line 22 def generate_constant_name(name) name.to_s.parameterize(separator: "_").classify end |
#mount(target, name) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/axn/mountable/helpers/class_builder.rb', line 15 def mount(target, name) namespace = Helpers::NamespaceManager.get_or_create_namespace(target) return unless should_register_constant?(namespace) build_and_configure_action_class(target, name, namespace) end |