Sha256: e619693f035b9524dfb90841dd5c3a5fe6bddfa16bfa407e08ab9d42a7ace089

Contents?: true

Size: 682 Bytes

Versions: 6

Compression:

Stored size: 682 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
          value = value.dup if value.respond_to?(:dup)
          value.freeze
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
koine-attributes-0.2.0 lib/koine/attributes/adapter/base.rb
koine-attributes-0.1.4 lib/koine/attributes/adapter/base.rb
koine-attributes-0.1.3 lib/koine/attributes/adapter/base.rb
koine-attributes-0.1.2 lib/koine/attributes/adapter/base.rb
koine-attributes-0.1.1 lib/koine/attributes/adapter/base.rb
koine-attributes-0.1.0 lib/koine/attributes/adapter/base.rb