Class: Plutonium::Query::Filter

Inherits:
Base
  • Object
show all
Defined in:
lib/plutonium/query/filter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#apply

Methods included from Definition::Presentable

#description, #icon, #label

Constructor Details

#initialize(key:) ⇒ Filter

Returns a new instance of Filter.



20
21
22
23
# File 'lib/plutonium/query/filter.rb', line 20

def initialize(key:)
  super()
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/plutonium/query/filter.rb', line 4

def key
  @key
end

Class Method Details

.lookup(type) ⇒ Class

Lookup a filter class by type symbol or return the class if already a Filter

Parameters:

  • type (Symbol, Class)

    The type symbol (e.g., :text, :select) or a Filter class

Returns:

  • (Class)

    The filter class



10
11
12
13
14
15
16
17
# File 'lib/plutonium/query/filter.rb', line 10

def lookup(type)
  return type if type.is_a?(Class) && type < Filter

  class_name = "Plutonium::Query::Filters::#{type.to_s.classify}"
  class_name.constantize
rescue NameError
  raise ArgumentError, "Unknown filter type: #{type}. Expected #{class_name} to exist."
end