class ActiveFedora::Indexing::Suffix

Public Class Methods

config() click to toggle source
# File lib/active_fedora/indexing/suffix.rb, line 47
def self.config
  # TODO: `:symbol' usage ought to be deprecated
  # See https://github.com/samvera/active_fedora/issues/1334
  @config ||= OpenStruct.new fields: [:type, :stored, :indexed, :multivalued],
                             suffix_delimiter: '_',
                             type_suffix: (lambda do |fields|
                                             type = fields.first
                                             case type
                                             when :string, :symbol
                                               's'
                                             when :text
                                               't'
                                             when :text_en
                                               'te'
                                             when :date, :time
                                               'dt'
                                             when :integer
                                               'i'
                                             when :boolean
                                               'b'
                                             when :long
                                               'lt'
                                             when :float, :big_decimal
                                               'f'
                                             else
                                               raise InvalidIndexDescriptor, "Invalid datatype `#{type.inspect}'. Must be one of: :date, :time, :text, :text_en, :string, :symbol, :integer, :boolean"
                                             end
                                           end),
                             stored_suffix: 's',
                             indexed_suffix: 'i',
                             multivalued_suffix: 'm'
end
new(*fields) click to toggle source
# File lib/active_fedora/indexing/suffix.rb, line 6
def initialize(*fields)
  @fields = fields.flatten
end

Public Instance Methods

config() click to toggle source
# File lib/active_fedora/indexing/suffix.rb, line 80
def config
  @config ||= self.class.config.dup
end
data_type() click to toggle source
# File lib/active_fedora/indexing/suffix.rb, line 26
def data_type
  @fields.first
end
has_field?(f) click to toggle source
# File lib/active_fedora/indexing/suffix.rb, line 22
def has_field?(f)
  (f.to_sym == :type) || @fields.include?(f.to_sym)
end
indexed?() click to toggle source
# File lib/active_fedora/indexing/suffix.rb, line 18
def indexed?
  has_field? :indexed
end
multivalued?() click to toggle source
# File lib/active_fedora/indexing/suffix.rb, line 10
def multivalued?
  has_field? :multivalued
end
stored?() click to toggle source
# File lib/active_fedora/indexing/suffix.rb, line 14
def stored?
  has_field? :stored
end
to_s() click to toggle source
# File lib/active_fedora/indexing/suffix.rb, line 30
def to_s
  raise InvalidIndexDescriptor, "Missing datatype for #{@fields}" unless data_type

  field_suffix = [config.suffix_delimiter]

  config.fields.select { |f| has_field? f }.each do |f|
    key = :"#{f}_suffix"
    field_suffix << if config.send(key).is_a? Proc
                      config.send(key).call(@fields)
                    else
                      config.send(key)
                    end
  end

  field_suffix.join
end