Class: Democritus::ClassBuilder::Commands::Attributes
- Inherits:
-
Democritus::ClassBuilder::Command
- Object
- Democritus::ClassBuilder::Command
- Democritus::ClassBuilder::Commands::Attributes
- Defined in:
- lib/democritus/class_builder/commands/attributes.rb
Overview
Command to assign attributes as part of the initialize method.
Commands Available Within the pre_deferment_operation collapse
-
#attribute(name:, **options) ⇒ Object
Exposes a mechanism for assigning individual attributes as part of the #attributes command.
Instance Method Summary collapse
-
#call ⇒ Object
Method that generates the behavior for the Attributes command.
-
#initialize(builder:, &pre_deferment_operation) ⇒ Attributes
constructor
A new instance of Attributes.
Constructor Details
#initialize(builder:, &pre_deferment_operation) ⇒ Attributes
Returns a new instance of Attributes.
16 17 18 19 20 |
# File 'lib/democritus/class_builder/commands/attributes.rb', line 16 def initialize(builder:, &pre_deferment_operation) self.builder = builder self.pre_deferment_operation = pre_deferment_operation self.attribute_names = [] end |
Instance Method Details
#attribute(name:, **options) ⇒ Object
Exposes a mechanism for assigning individual attributes as part of the #attributes command.
69 70 71 72 73 |
# File 'lib/democritus/class_builder/commands/attributes.rb', line 69 def attribute(name:, **) name = name.to_sym attribute_names << name builder.attribute(name: name, **) end |
#call ⇒ Object
Method that generates the behavior for the Attributes command
28 29 30 31 32 33 34 |
# File 'lib/democritus/class_builder/commands/attributes.rb', line 28 def call # In order to register any nested attributes, the pre_deferment_operation must be performed # outside of the defer method call. If it were done inside the defer block, then the pre_deferment_operation # might get lost. execute_pre_deferment_operation defer { |subject| configure(subject: subject) } end |