Class: Democritus::ClassBuilder::Commands::Attribute
- Inherits:
-
Democritus::ClassBuilder::Command
- Object
- Democritus::ClassBuilder::Command
- Democritus::ClassBuilder::Commands::Attribute
- Defined in:
- lib/democritus/class_builder/commands/attribute.rb
Overview
Command to assign an attribute to the given built class.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#call ⇒ Object
Generate the code for the attribute.
-
#initialize(name:, **options) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(name:, **options) ⇒ Attribute
Returns a new instance of Attribute.
11 12 13 14 15 |
# File 'lib/democritus/class_builder/commands/attribute.rb', line 11 def initialize(name:, **) self.builder = .fetch(:builder) self.name = name self. = end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'lib/democritus/class_builder/commands/attribute.rb', line 17 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
18 19 20 |
# File 'lib/democritus/class_builder/commands/attribute.rb', line 18 def @options end |
Instance Method Details
#call ⇒ Object
Generate the code for the attribute
:reek:NestedIterators: { exclude: [ ‘Democritus::ClassBuilder::Commands::Attribute#call’ ] }
24 25 26 27 28 29 30 31 32 |
# File 'lib/democritus/class_builder/commands/attribute.rb', line 24 def call defer do |subject| subject.module_exec(@name) do |name| attr_reader name private attr_writer name end end end |