class ActiveFedora::Indexing::Descriptor

Attributes

index_type[R]

Public Class Methods

new(*args) click to toggle source
# File lib/active_fedora/indexing/descriptor.rb, line 5
def initialize(*args)
  if args.last.is_a? Hash
    opts = args.pop
    @converter = opts[:converter]
    @type_required = opts[:requires_type]
  end
  @index_type = args
  raise InvalidIndexDescriptor, "Invalid index type passed.  It should be an array like [:string, :indexed, :stored, :multivalued]. You provided: `#{@index_type}'" unless index_type.is_a? Array
end

Public Instance Methods

evaluate_suffix(field_type) click to toggle source
# File lib/active_fedora/indexing/descriptor.rb, line 28
def evaluate_suffix(field_type)
  Suffix.new(index_type.first.is_a?(Proc) ? index_type.first.call(field_type) : index_type.dup)
end
name_and_converter(field_name, args = nil) click to toggle source
# File lib/active_fedora/indexing/descriptor.rb, line 15
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?() click to toggle source
# File lib/active_fedora/indexing/descriptor.rb, line 24
def type_required?
  @type_required
end

Protected Instance Methods

converter(field_type) click to toggle source
# File lib/active_fedora/indexing/descriptor.rb, line 39
def converter(field_type)
  @converter&.call(field_type)
end
suffix(field_type) click to toggle source

Suffix can be overridden if you want a different method of grabbing the suffix

# File lib/active_fedora/indexing/descriptor.rb, line 35
def suffix(field_type)
  evaluate_suffix(field_type).to_s
end