Class: Dbee::Query::Filters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dbee/query/filters/base.rb

Overview

Defines the shared implementation for all filters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_path:, value: nil) ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
# File 'lib/dbee/query/filters/base.rb', line 19

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

Instance Attribute Details

#key_pathObject (readonly)

Returns the value of attribute key_path.



17
18
19
# File 'lib/dbee/query/filters/base.rb', line 17

def key_path
  @key_path
end

#valueObject (readonly)

Returns the value of attribute value.



17
18
19
# File 'lib/dbee/query/filters/base.rb', line 17

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



39
40
41
42
# File 'lib/dbee/query/filters/base.rb', line 39

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

#==(other) ⇒ Object Also known as: eql?



32
33
34
35
36
# File 'lib/dbee/query/filters/base.rb', line 32

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

#hashObject



28
29
30
# File 'lib/dbee/query/filters/base.rb', line 28

def hash
  "#{self.class.name}#{key_path}#{value}".hash
end