Sha256: 9ebcdef1a603fe79d7b754c52f28d18fe0f9a28470866918e227ae5c07b077bd

Contents?: true

Size: 994 Bytes

Versions: 22

Compression:

Stored size: 994 Bytes

Contents

module ActiveFedora
  module WithMetadata
    extend ActiveSupport::Concern
    extend ActiveSupport::Autoload

    autoload :MetadataNode

    def metadata_node
      @metadata_node ||= self.class.metadata_schema.new(self)
    end

    def create_or_update(*)
      return unless super && !new_record?
      metadata_node.metadata_uri = described_by # TODO: only necessary if the URI was < > before
      metadata_node.save # TODO if changed?
    end

    module ClassMethods
      def metadata(&block)
        metadata_schema.exec_block(&block)
      end

      def metadata_schema
        @metadata_schema ||= MetadataNode(self)
      end

      # Make a subclass of MetadataNode named GeneratedMetadataSchema and set its
      # parent_class attribute to have the value of the current class.
      def MetadataNode(parent_klass)
        klass = const_set(:GeneratedMetadataSchema, Class.new(MetadataNode))
        klass.parent_class = parent_klass
        klass
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
active-fedora-9.7.3 lib/active_fedora/with_metadata.rb
active-fedora-9.7.2 lib/active_fedora/with_metadata.rb
active-fedora-10.0.0.beta1 lib/active_fedora/with_metadata.rb
active-fedora-9.13.0 lib/active_fedora/with_metadata.rb
active-fedora-9.12.0 lib/active_fedora/with_metadata.rb
active-fedora-9.11.0 lib/active_fedora/with_metadata.rb
active-fedora-9.10.4 lib/active_fedora/with_metadata.rb
active-fedora-9.10.3 lib/active_fedora/with_metadata.rb
active-fedora-9.10.2 lib/active_fedora/with_metadata.rb
active-fedora-9.10.1 lib/active_fedora/with_metadata.rb
active-fedora-9.10.0 lib/active_fedora/with_metadata.rb
active-fedora-9.10.0.pre2 lib/active_fedora/with_metadata.rb
active-fedora-9.10.0.pre1 lib/active_fedora/with_metadata.rb
active-fedora-9.9.1 lib/active_fedora/with_metadata.rb
active-fedora-9.9.0 lib/active_fedora/with_metadata.rb
active-fedora-9.8.2 lib/active_fedora/with_metadata.rb
active-fedora-9.8.1 lib/active_fedora/with_metadata.rb
active-fedora-9.8.0 lib/active_fedora/with_metadata.rb
active-fedora-9.7.1 lib/active_fedora/with_metadata.rb
active-fedora-9.7.0 lib/active_fedora/with_metadata.rb