Sha256: 5b14be006a86ed2c4b179e0701e662ace4d7da89b46cd3c2d41f380d619c2826

Contents?: true

Size: 813 Bytes

Versions: 11

Compression:

Stored size: 813 Bytes

Contents

# frozen_string_literal: true

require 'kind/basic'
require 'kind/__lib__/attributes'

module Kind
  module ImmutableAttributes
    require 'kind/immutable_attributes/initializer'
    require 'kind/immutable_attributes/reader'

    module ClassMethods
      def __attributes__ # :nodoc:
        @__attributes__ ||= {}
      end

      def attribute(name, kind = nil, default: UNDEFINED, visibility: :public)
        __attributes__[ATTRIBUTES.name!(name)] = ATTRIBUTES.value(kind, default, visibility)

        attr_reader(name)

        private(name) if visibility == :private
        protected(name) if visibility == :protected

        name
      end
    end

    def self.included(base)
      base.extend(ClassMethods)
      base.send(:include, Reader)
      base.send(:include, Initializer)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
kind-5.10.0 lib/kind/immutable_attributes.rb
kind-5.9.0 lib/kind/immutable_attributes.rb
kind-5.8.1 lib/kind/immutable_attributes.rb
kind-5.8.0 lib/kind/immutable_attributes.rb
kind-5.7.0 lib/kind/immutable_attributes.rb
kind-5.6.0 lib/kind/immutable_attributes.rb
kind-5.5.0 lib/kind/immutable_attributes.rb
kind-5.4.1 lib/kind/immutable_attributes.rb
kind-5.4.0 lib/kind/immutable_attributes.rb
kind-5.3.0 lib/kind/immutable_attributes.rb
kind-5.2.0 lib/kind/immutable_attributes.rb