Class: Sunspot::CompositeSetup

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

Overview

The CompositeSetup class encapsulates a collection of setups, and responds to a subset of the methods that Setup responds to (in particular, the methods required to build queries).

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ CompositeSetup

Returns a new instance of CompositeSetup.



12
13
14
# File 'lib/sunspot/composite_setup.rb', line 12

def initialize(types)
  @types = types
end

Instance Method Details

#dynamic_field_factory(field_name) ⇒ Object

Get a dynamic field factory for the given base name.

Returns

DynamicFieldFactory

Factory for dynamic fields with the given base name

Raises

UnrecognizedFieldError

If the given base name is not configured as a dynamic field for the types being queried



93
94
95
96
97
98
# File 'lib/sunspot/composite_setup.rb', line 93

def dynamic_field_factory(field_name)
  dynamic_field_factories_hash[field_name.to_sym] || raise(
    UnrecognizedFieldError,
    "No dynamic field configured for #{@types * ', '} with name #{field_name.inspect}"
  )
end

#field(field_name) ⇒ Object

Get a Sunspot::AttributeField instance corresponding to the given field name

Parameters

field_name<Symbol>

The public field name for which to find a field

Returns

Sunspot::AttributeField The field object corresponding to the given name

Raises

ArgumentError

If the given field name is not configured for the types being queried



74
75
76
77
78
79
# File 'lib/sunspot/composite_setup.rb', line 74

def field(field_name) #:nodoc:
  fields_hash[field_name.to_sym] || raise(
    UnrecognizedFieldError,
    "No field configured for #{@types * ', '} with name '#{field_name}'"
  )
end

#setupsObject

Collection of Setup objects for the enclosed types

Returns

Array

Collection of Setup objects



23
24
25
# File 'lib/sunspot/composite_setup.rb', line 23

def setups
  @setups ||= @types.map { |type| Setup.for(type) }
end

#text_field(field_name) ⇒ Object

Get a text field object by its public name. A field will be returned if it is configured for any of the enclosed types.

Returns

Sunspot::FulltextField

Text field with the given public name

Raises

UnrecognizedFieldError

If no field with that name is configured for any of the enclosed types.



51
52
53
54
55
56
# File 'lib/sunspot/composite_setup.rb', line 51

def text_field(field_name)
  text_fields_hash[field_name.to_sym] || raise(
    UnrecognizedFieldError,
    "No text field configured for #{@types * ', '} with name '#{field_name}'"
  )
end

#text_fieldsObject

Collection of all text fields configured for any of the enclosed types.

Returns

Array

Text fields configured for the enclosed types



107
108
109
# File 'lib/sunspot/composite_setup.rb', line 107

def text_fields
  @text_fields ||= text_fields_hash.values
end

#type_namesObject

Return the names of the encapsulated types

Returns

Array

Collection of class names



34
35
36
# File 'lib/sunspot/composite_setup.rb', line 34

def type_names
  @type_names ||= @types.map { |clazz| clazz.name }
end