Class: Compass::Search::Provider

Inherits:
Object
  • Object
show all
Includes:
JsonFormatter, Rendering
Defined in:
lib/compass/search/provider.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rendering

#render, #view_context

Constructor Details

#initialize(**context) ⇒ Provider

Returns a new instance of Provider.



9
10
11
12
# File 'lib/compass/search/provider.rb', line 9

def initialize(**context)
  @context = context
  context.each { |key, value| define_singleton_method(key) { value } }
end

Class Method Details

.as_jsonObject



25
26
27
28
29
30
31
# File 'lib/compass/search/provider.rb', line 25

def self.as_json(*)
  {
    provider: name,
    label: label,
    search_options: search_options
  }
end

.labelObject



23
# File 'lib/compass/search/provider.rb', line 23

def self.label = name.to_s.gsub(/(Provider|Search)/i, "").pluralize

Instance Method Details

#fetch_records(_query) ⇒ Object



18
# File 'lib/compass/search/provider.rb', line 18

def fetch_records(_query) = must_implement(:fetch_records)

#search(query) ⇒ Object



14
15
16
# File 'lib/compass/search/provider.rb', line 14

def search(query)
  fetch_records(query).map { |record| format(record) }
end