Class: MySQL::Search::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql/search/source.rb

Overview

Represents a source for search indexing.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Source

Returns a new instance of Source.



30
31
32
# File 'lib/mysql/search/source.rb', line 30

def initialize(model)
  @model = model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



11
12
13
# File 'lib/mysql/search/source.rb', line 11

def model
  @model
end

Class Method Details

.joins_argsObject



25
26
27
28
# File 'lib/mysql/search/source.rb', line 25

def self.joins_args
  combined_config = _config.values.reduce(&:deep_merge)
  extract_joins_args(combined_config)
end

.modelObject



21
22
23
# File 'lib/mysql/search/source.rb', line 21

def self.model
  _model || name.delete_suffix('Source').constantize
end

.schema(config) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/mysql/search/source.rb', line 13

def self.schema(config)
  self._model = model
  self._config = _config.merge(config)
  self._callbacks = ::MySQL::Search::Callbacks.new(_model, _config)

  _callbacks.assign
end

Instance Method Details

#extractObject



34
35
36
37
38
39
40
41
# File 'lib/mysql/search/source.rb', line 34

def extract
  _config.each_with_object({}) do |(search_index_attribute, grabber_config), extracted|
    validate_search_index_attribute!(search_index_attribute)

    grabbed_data = Grabber.new(model, grabber_config).grab
    extracted[search_index_attribute] = grabbed_data.compact.join(' ').squish
  end
end