Sha256: c353fe8822c54f85e178dd31abeafbc6c674948ffef577ea7f98d215d5963f90

Contents?: true

Size: 1001 Bytes

Versions: 1

Compression:

Stored size: 1001 Bytes

Contents

require 'ice_nine'
require 'dry/core/deprecations'

module Dry
  class Struct
    extend Core::Deprecations[:'dry-struct']

    # {Value} objects behave like {Struct}s but *deeply frozen*
    # using [`ice_nine`](https://github.com/dkubb/ice_nine)
    #
    # @example
    #   class Location < Dry::Struct::Value
    #     attribute :lat, Types::Float
    #     attribute :lng, Types::Float
    #   end
    #
    #   loc1 = Location.new(lat: 1.23, lng: 4.56)
    #   loc2 = Location.new(lat: 1.23, lng: 4.56)
    #
    #   loc1.frozen? #=> true
    #   loc2.frozen? #=> true
    #   loc1 == loc2 #=> true
    #
    # @see https://github.com/dkubb/ice_nine
    class Value < self
      # @param (see ClassInterface#new)
      # @return [Value]
      # @see https://github.com/dkubb/ice_nine
      def self.new(*)
        ::IceNine.deep_freeze(super)
      end

      # @api private
      # @return [Boolean]
      def self.value?
        true
      end
    end

    deprecate_constant :Value
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-struct-1.2.0 lib/dry/struct/value.rb