Sha256: 781cf93f24e8766a9147af7d241327c6d191d59277b1b9d5722c5c6b18114d23

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 KB

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
          "#{self.class.name}#{key_path}#{value}".hash
        end

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

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
dbee-3.1.0 lib/dbee/query/filters/base.rb
dbee-3.0.0 lib/dbee/query/filters/base.rb
dbee-2.1.1 lib/dbee/query/filters/base.rb
dbee-2.1.0 lib/dbee/query/filters/base.rb
dbee-2.1.0.pre.alpha lib/dbee/query/filters/base.rb
dbee-2.0.3 lib/dbee/query/filters/base.rb
dbee-2.0.2 lib/dbee/query/filters/base.rb
dbee-2.0.1 lib/dbee/query/filters/base.rb
dbee-2.0.0 lib/dbee/query/filters/base.rb
dbee-2.0.0.pre.alpha lib/dbee/query/filters/base.rb
dbee-1.2.1 lib/dbee/query/filters/base.rb
dbee-1.2.0 lib/dbee/query/filters/base.rb
dbee-1.1.0 lib/dbee/query/filters/base.rb