Class: Compass::Search::Provider

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MustImplement

#must_implement

Methods included from Rendering

#render, #view_context

Constructor Details

#initialize(**context) ⇒ Provider

Returns a new instance of Provider.



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

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

Class Method Details

.as_jsonObject



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

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

.labelObject



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

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

Instance Method Details

#fetch_records(_query) ⇒ Object



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

def fetch_records(_query) = must_implement(:fetch_records)

#search(query) ⇒ Object



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

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