Module: Sunspot::Field::Buildable

Included in:
DynamicField, StaticField
Defined in:
lib/sunspot/field.rb

Overview

This module adds a (class) method for building a field definition given a standard set of arguments

Instance Method Summary collapse

Instance Method Details

#build(name, type, options = {}, &block) ⇒ Object

Build a field definition based on a standard argument API. If a block is passed, use virtual extraction; otherwise, use attribute extraction.



93
94
95
96
97
98
99
100
101
# File 'lib/sunspot/field.rb', line 93

def build(name, type, options = {}, &block)
  data_extractor =
    if block
      DataExtractor::BlockExtractor.new(&block)
    else
      DataExtractor::AttributeExtractor.new(options.delete(:using) || name)
    end
  new(name, type, data_extractor, options)
end