Sha256: 07393bc654a55ddd2fc68af3f8275e224bc6f15cc1849d568bf91895d46bc811

Contents?: true

Size: 948 Bytes

Versions: 2

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

#
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module Dbee
  class Query
    class Filters
      # Defines the shared implementation for all filters.
      class Base
        acts_as_hashable

        attr_reader :key_path, :value

        def initialize(key_path:, value: nil)
          raise ArgumentError, 'key_path is required' if key_path.to_s.empty?

          @key_path = KeyPath.get(key_path)
          @value    = value

          freeze
        end

        def hash
          "#{key_path}#{value}".hash
        end

        def ==(other)
          other.key_path == key_path && other.value == value
        end
        alias eql? ==

        def <=>(other)
          "#{key_path}#{value}" <=> "#{other.key_path}#{other.value}"
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dbee-1.0.3 lib/dbee/query/filters/base.rb
dbee-1.0.2 lib/dbee/query/filters/base.rb