Sha256: 6b7fd82abdd881aa88c9b8fdc466dd7160ed13d0c0dbabf6f1f647abacc4b300

Contents?: true

Size: 1.58 KB

Versions: 13

Compression:

Stored size: 1.58 KB

Contents

require "nom"

module ActiveFedora
  class NomDatastream < File
    include Datastreams::NokogiriDatastreams
    extend Deprecation

    def self.set_terminology(options = {}, &block)
      @terminology_options = options || {}
      @terminology = block
    end

    def initialize(*args)
      super
      Deprecation.warn(NomDatastream, "NomDatastream is deprecated and will be removed in ActiveFedora 11")
    end

    class << self
      attr_reader :terminology_options
    end

    class << self
      attr_reader :terminology
    end

    def self.decorate_ng_xml(xml)
      xml.set_terminology terminology_options, &terminology
      xml.nom!
      xml
    end

    def serialize!
      self.content = @ng_xml.to_s if @ng_xml
    end

    def to_solr
      solr_doc = {}

      ng_xml.terminology.flatten.select { |x| x.options[:index] }.each do |term|
        term.values.each do |v|
          Array(term.options[:index]).each do |index_as|
            solr_doc[index_as] ||= []
            solr_doc[index_as] << if v.is_a? Nokogiri::XML::Node
                                    v.text
                                  else
                                    v
                                  end
          end
        end
      end

      solr_doc
    end

    def method_missing(method, *args, &block)
      if ng_xml.respond_to? method
        ng_xml.send(method, *args, &block)
      else
        super
      end
    end

    def respond_to?(*args)
      super || self.class.terminology.respond_to?(*args)
    end

    protected

      def default_mime_type
        'text/xml'
      end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
active-fedora-10.3.0 lib/active_fedora/nom_datastream.rb
active-fedora-10.3.0.rc2 lib/active_fedora/nom_datastream.rb
active-fedora-10.3.0.rc1 lib/active_fedora/nom_datastream.rb
active-fedora-11.0.0.rc6 lib/active_fedora/nom_datastream.rb
active-fedora-10.2.1 lib/active_fedora/nom_datastream.rb
active-fedora-11.0.0.rc5 lib/active_fedora/nom_datastream.rb
active-fedora-11.0.0.rc4 lib/active_fedora/nom_datastream.rb
active-fedora-10.2.0 lib/active_fedora/nom_datastream.rb
active-fedora-11.0.0.rc3 lib/active_fedora/nom_datastream.rb
active-fedora-11.0.0.rc2 lib/active_fedora/nom_datastream.rb
active-fedora-11.0.0.rc1 lib/active_fedora/nom_datastream.rb
active-fedora-10.1.0 lib/active_fedora/nom_datastream.rb
active-fedora-10.1.0.rc1 lib/active_fedora/nom_datastream.rb