Class: MySQL::Search::Grabber

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

Overview

Extracts and formats data for search indexing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, config) ⇒ Grabber

Returns a new instance of Grabber.



9
10
11
12
# File 'lib/mysql/search/grabber.rb', line 9

def initialize(model, config)
  @model = model
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/mysql/search/grabber.rb', line 7

def config
  @config
end

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/mysql/search/grabber.rb', line 7

def model
  @model
end

Instance Method Details

#grabObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/mysql/search/grabber.rb', line 14

def grab
  config.flat_map do |attr_or_relation, format_or_config|
    case format_or_config
    when Hash then forward(attr_or_relation, format_or_config)
    when Symbol, String, Array, Proc then format(attr_or_relation, format_or_config)
    else
      raise(ArgumentError, "unknown config value: '#{format_or_config.inspect}'")
    end
  end
end