Class: Sunspot::Schema::DynamicField
- Inherits:
-
Object
- Object
- Sunspot::Schema::DynamicField
- Defined in:
- lib/sunspot/schema.rb
Overview
Represents a dynamic field (in the Solr schema sense, not the Sunspot sense).
Instance Method Summary collapse
-
#initialize(type, field_variants) ⇒ DynamicField
constructor
A new instance of DynamicField.
-
#method_missing(name, *args, &block) ⇒ Object
Implement magic methods to ask if a field is of a particular variant.
-
#name ⇒ Object
Name of the field in the schema.
-
#type ⇒ Object
Name of the type as defined in the schema.
Constructor Details
#initialize(type, field_variants) ⇒ DynamicField
Returns a new instance of DynamicField.
115 116 117 |
# File 'lib/sunspot/schema.rb', line 115 def initialize(type, field_variants) @type, @field_variants = type, field_variants end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Implement magic methods to ask if a field is of a particular variant. Returns “true” if the field is of that variant and “false” otherwise.
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/sunspot/schema.rb', line 138 def method_missing(name, *args, &block) if name.to_s =~ /\?$/ && args.empty? if @field_variants.any? { |variant| "#{variant.attribute}?" == name.to_s } 'true' else 'false' end else super(name.to_sym, *args, &block) end end |
Instance Method Details
#name ⇒ Object
Name of the field in the schema
122 123 124 125 |
# File 'lib/sunspot/schema.rb', line 122 def name variant_suffixes = @field_variants.map { |variant| variant.suffix }.join "*_#{@type.suffix}#{variant_suffixes}" end |
#type ⇒ Object
Name of the type as defined in the schema
130 131 132 |
# File 'lib/sunspot/schema.rb', line 130 def type @type.name end |