Sha256: 450abcf6a9f710eb8cb6fcbb35886901fde4936ef323e1bcf5b4bb7845403a01

Contents?: true

Size: 739 Bytes

Versions: 3

Compression:

Stored size: 739 Bytes

Contents

module Koine
  module Attributes
    module Adapter
      class Base
        def coerce(*_values)
          raise NotImplementedError
        end

        def default_value
          @default_value.respond_to?(:call) &&
            @default_value.call ||
            @default_value
        end

        def with_default_value(value = nil, &block)
          @default_value = value
          @default_value = block if block
          self
        end

        protected

        # duplicates if possible and freezes object
        def secure
          value = yield

          unless value.is_a?(::Symbol)
            value = value.dup if value.respond_to?(:dup)
          end

          value.freeze
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
koine-attributes-0.2.3 lib/koine/attributes/adapter/base.rb
koine-attributes-0.2.2 lib/koine/attributes/adapter/base.rb
koine-attributes-0.2.1 lib/koine/attributes/adapter/base.rb