Class: Sunspot::DataExtractor::BlockExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot/data_extractor.rb

Overview

BlockExtractors extract data by evaluating a block in the context of the object instance, or if the block takes an argument, by passing the object as the argument to the block. Either way, the return value of the block is the value returned by the extractor.

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ BlockExtractor

Returns a new instance of BlockExtractor.



28
29
30
# File 'lib/sunspot/data_extractor.rb', line 28

def initialize(&block)
  @block = block
end

Instance Method Details

#value_for(object) ⇒ Object



32
33
34
# File 'lib/sunspot/data_extractor.rb', line 32

def value_for(object)
  Util.instance_eval_or_call(object, &@block)
end