Class: Metka::TagsQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/metka/tags_query.rb

Constant Summary collapse

OPERATORS =

PostgreSQL array operators; also the source of truth for valid match modes, so an unknown mode raises KeyError on either adapter.

{ all: "@>", any: "&&" }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(match: :all) ⇒ TagsQuery

Returns a new instance of TagsQuery.



9
10
11
12
# File 'lib/metka/tags_query.rb', line 9

def initialize(match: :all)
  OPERATORS.fetch(match)
  @match = match
end

Instance Method Details

#call(model, column_name, tag_list) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/metka/tags_query.rb', line 14

def call(model, column_name, tag_list)
  if model.connection.adapter_name.match?(/sqlite/i)
    sqlite(model, column_name, tag_list)
  else
    postgresql(model, column_name, tag_list)
  end
end