Sha256: f2546934bd41d5b8ff7823acf7ba3cadf35a140b857d57839c026eabf2cb9877

Contents?: true

Size: 834 Bytes

Versions: 1

Compression:

Stored size: 834 Bytes

Contents

require 'democritus/class_builder/command'

module Democritus
  class ClassBuilder
    module Commands
      # Command to assign an attribute to the given built class.
      class Attribute < ::Democritus::ClassBuilder::Command
        def initialize(name:, **options)
          self.builder = options.fetch(:builder)
          self.name = name
          self.options = options
        end

        attr_reader :name, :options

        # :reek:NestedIterators: { exclude: [ 'Democritus::ClassBuilder::Commands::Attribute#call' ] }
        def call
          defer do |subject|
            subject.module_exec(@name) do |name|
              attr_reader name
              private
              attr_writer name
            end
          end
        end

        private

        attr_writer :name, :options
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
democritus-0.2.0 lib/democritus/class_builder/commands/attribute.rb