Sha256: 7ce0ee4f45e56272af7c5bf20d0437b4f9aff6c64f983451241c3d77b9504b15

Contents?: true

Size: 839 Bytes

Versions: 55

Compression:

Stored size: 839 Bytes

Contents

# frozen_string_literal: true

# Monkey patch ActiveFedora::RelsExtDatastream.short_predicate to
# create missing mappings on the fly.

module ActiveFedora
  class RelsExtDatastream
    def self.short_predicate(predicate)
      # for this regex to short-circuit correctly, namespaces must be sorted into descending order by length
      if match = /^(#{Predicates.predicate_mappings.keys.sort.reverse.join('|')})(.+)$/.match(predicate.to_str)
        namespace = match[1]
        predicate = match[2]
        ns_mapping = Predicates.predicate_mappings[namespace] ||= {}
        pred = ns_mapping.invert[predicate]
        if pred.nil?
          pred = predicate.underscore.to_sym
          ns_mapping[pred] = predicate
        end
        pred
      else
        raise "Unable to parse predicate: #{predicate}"
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
dor-services-9.6.2 lib/dor/utils/predicate_patch.rb
dor-services-9.6.1 lib/dor/utils/predicate_patch.rb
dor-services-9.6.0 lib/dor/utils/predicate_patch.rb
dor-services-9.5.0 lib/dor/utils/predicate_patch.rb
dor-services-9.4.0 lib/dor/utils/predicate_patch.rb
dor-services-9.3.0 lib/dor/utils/predicate_patch.rb
dor-services-9.2.1 lib/dor/utils/predicate_patch.rb
dor-services-9.2.0 lib/dor/utils/predicate_patch.rb
dor-services-9.1.0 lib/dor/utils/predicate_patch.rb
dor-services-9.0.0 lib/dor/utils/predicate_patch.rb
dor-services-8.6.0 lib/dor/utils/predicate_patch.rb
dor-services-8.5.0 lib/dor/utils/predicate_patch.rb
dor-services-8.4.0 lib/dor/utils/predicate_patch.rb
dor-services-8.3.0 lib/dor/utils/predicate_patch.rb
dor-services-8.2.0 lib/dor/utils/predicate_patch.rb
dor-services-8.1.1 lib/dor/utils/predicate_patch.rb
dor-services-8.1.0 lib/dor/utils/predicate_patch.rb
dor-services-8.0.0 lib/dor/utils/predicate_patch.rb
dor-services-7.2.4 lib/dor/utils/predicate_patch.rb
dor-services-7.2.3 lib/dor/utils/predicate_patch.rb