Class: Solrizer::Descriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/solrizer/descriptor.rb

Direct Known Subclasses

StringDescriptor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Descriptor

Returns a new instance of Descriptor.



4
5
6
7
8
9
10
11
12
# File 'lib/solrizer/descriptor.rb', line 4

def initialize(*args)
  if args.last.kind_of? Hash
    opts = args.pop
    @converter = opts[:converter] 
    @type_required = opts[:requires_type] 
  end
  @index_type = args
  raise Solrizer::InvalidIndexDescriptor, "Invalid index type passed to Sorizer.solr_name.  It should be an array like [:string, :indexed, :stored, :multivalued]. You provided: `#{@index_type}'" unless index_type.kind_of? Array
end

Instance Attribute Details

#index_typeObject (readonly)

Returns the value of attribute index_type.



3
4
5
# File 'lib/solrizer/descriptor.rb', line 3

def index_type
  @index_type
end

Instance Method Details

#evaluate_suffix(field_type) ⇒ Object



27
28
29
# File 'lib/solrizer/descriptor.rb', line 27

def evaluate_suffix(field_type)
  Suffix.new(index_type.first.kind_of?(Proc) ? index_type.first.call(field_type) : index_type.dup)
end

#name_and_converter(field_name, args = nil) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/solrizer/descriptor.rb', line 14

def name_and_converter(field_name, args=nil)
  args ||= {}
  field_type = args[:type]
  if type_required?
    raise ArgumentError, "Must provide a :type argument when index_type is `#{self}' for #{field_name}" unless field_type
  end
  [field_name.to_s + suffix(field_type), converter(field_type)]
end

#type_required?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/solrizer/descriptor.rb', line 23

def type_required?
  @type_required
end