Sha256: 331f5f3b6f09cbf832246ef5b6096e3a8be3bf5c4232c34de7a78861acefd916

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 KB

Contents

module Sunspot
  # 
  # DataExtractors present an internal API for the indexer to use to extract
  # field values from models for indexing. They must implement the #value_for
  # method, which takes an object and returns the value extracted from it.
  #
  module DataExtractor #:nodoc: all
    # 
    # AttributeExtractors extract data by simply calling a method on the block.
    #
    class AttributeExtractor
      def initialize(attribute_name)
        @attribute_name = attribute_name
      end

      def value_for(object)
        object.send(@attribute_name)
      end
    end

    # 
    # 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.
    #
    class BlockExtractor
      def initialize(&block)
        @block = block
      end

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

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
outoftime-sunspot-0.8.0 lib/sunspot/data_extractor.rb
outoftime-sunspot-0.8.1 lib/sunspot/data_extractor.rb
outoftime-sunspot-0.8.2 lib/sunspot/data_extractor.rb
outoftime-sunspot-0.8.3 lib/sunspot/data_extractor.rb
outoftime-sunspot-0.8.4 lib/sunspot/data_extractor.rb
outoftime-sunspot-0.8.5 lib/sunspot/data_extractor.rb
outoftime-sunspot-0.8.8 lib/sunspot/data_extractor.rb
outoftime-sunspot-0.8.9 lib/sunspot/data_extractor.rb
pallan-sunspot-0.8.3 lib/sunspot/data_extractor.rb