Sha256: f9b2d1dfb32fab2fdab7405da2704c2bf4a0c351fb39d675776f92b1c38df1b1

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Support
    class UniqueValue
      ##
      # @!attribute [r] label
      #   @return [String]
      #
      attr_reader :label

      ##
      # @param label [String]
      # @return [void]
      #
      def initialize(label = default_label)
        @label = label
      end

      ##
      # @param other [Object] Can be any type.
      # @return [Boolean]
      #
      # @internal
      #   NOTE: Every single Ruby object responds to `object_id`.
      #
      def ==(other)
        return unless other.instance_of?(self.class)

        object_id == other.object_id
      end

      ##
      # @param other [Object] Can be any type.
      # @return [Boolean]
      #
      def ===(other)
        self == other
      end

      ##
      # @param other [Object] Can be any type.
      # @return [Boolean]
      #
      def eql?(other)
        self == other
      end

      ##
      # @return [String]
      #
      def inspect
        return default_label if label.nil?
        return default_label if label.empty?

        label
      end

      private

      ##
      # @return [String]
      #
      def default_label
        "unique_value_#{object_id}"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
convenient_service-0.17.0 lib/convenient_service/support/unique_value.rb
convenient_service-0.16.0 lib/convenient_service/support/unique_value.rb
convenient_service-0.15.0 lib/convenient_service/support/unique_value.rb
convenient_service-0.14.0 lib/convenient_service/support/unique_value.rb
convenient_service-0.13.0 lib/convenient_service/support/unique_value.rb
convenient_service-0.12.0 lib/convenient_service/support/unique_value.rb