Sha256: 5428bc2fe1ac028db7ccf3df6096e226351097961d21359658a874ceaeee1c6b

Contents?: true

Size: 1.28 KB

Versions: 78

Compression:

Stored size: 1.28 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

    # 
    # Constant data extractors simply return the same value for every object.
    #
    class Constant
      def initialize(value)
        @value = value
      end

      def value_for(object)
        @value
      end
    end
  end
end

Version data entries

78 entries across 78 versions & 15 rubygems

Version Path
sunspot-2.3.0 lib/sunspot/data_extractor.rb
sunspot-2.2.8 lib/sunspot/data_extractor.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/lib/sunspot/data_extractor.rb
sunspot-2.2.7 lib/sunspot/data_extractor.rb
sunspot-2.2.6 lib/sunspot/data_extractor.rb
sunspot-2.2.5 lib/sunspot/data_extractor.rb
sunspot-2.2.4 lib/sunspot/data_extractor.rb
sunspot-2.2.3 lib/sunspot/data_extractor.rb
sunspot-2.2.2 lib/sunspot/data_extractor.rb
sunspot-2.2.1 lib/sunspot/data_extractor.rb
sunspot-2.2.0 lib/sunspot/data_extractor.rb
benjaminkrause-sunspot-0.9.7 lib/sunspot/data_extractor.rb
benjaminkrause-sunspot-0.9.8 lib/sunspot/data_extractor.rb
sunspot-2.1.1 lib/sunspot/data_extractor.rb
sunspot-2.1.0 lib/sunspot/data_extractor.rb
sunspot-2.0.0 lib/sunspot/data_extractor.rb
sunspot-2.0.0.pre.130115 lib/sunspot/data_extractor.rb
gojee-sunspot-2.0.5 lib/sunspot/data_extractor.rb
sunspot-2.0.0.pre.120925 lib/sunspot/data_extractor.rb
sunspot_solr-2.0.0.pre.120924 sunspot/lib/sunspot/data_extractor.rb