Class: ActiveFedora::Indexing::Descriptor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Descriptor

Returns a new instance of Descriptor.



5
6
7
8
9
10
11
12
13
# 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

Instance Attribute Details

#index_typeObject (readonly)

Returns the value of attribute index_type.



4
5
6
# File 'lib/active_fedora/indexing/descriptor.rb', line 4

def index_type
  @index_type
end

Instance Method Details

#evaluate_suffix(field_type) ⇒ Object



28
29
30
# 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) ⇒ Object



15
16
17
18
19
20
21
22
# 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?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/active_fedora/indexing/descriptor.rb', line 24

def type_required?
  @type_required
end