Class: Democritus::ClassBuilder::Commands::Attribute

Inherits:
Democritus::ClassBuilder::Command show all
Defined in:
lib/democritus/class_builder/commands/attribute.rb

Overview

Command to assign an attribute to the given built class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Democritus::ClassBuilder::Command

#defer

Constructor Details

#initialize(name:, **options) ⇒ Attribute

Returns a new instance of Attribute.



8
9
10
11
12
# File 'lib/democritus/class_builder/commands/attribute.rb', line 8

def initialize(name:, **options)
  self.builder = options.fetch(:builder)
  self.name = name
  self.options = options
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/democritus/class_builder/commands/attribute.rb', line 14

def name
  @name
end

#optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/democritus/class_builder/commands/attribute.rb', line 14

def options
  @options
end

Instance Method Details

#callObject

:reek:NestedIterators: { exclude: [ ‘Democritus::ClassBuilder::Commands::Attribute#call’ ] }



17
18
19
20
21
22
23
24
25
# File 'lib/democritus/class_builder/commands/attribute.rb', line 17

def call
  defer do |subject|
    subject.module_exec(@name) do |name|
      attr_reader name
      private
      attr_writer name
    end
  end
end