Sha256: f55dd3b67b74f2c205b1e802fb388cd13638a87646671d69cf15204b4873693a

Contents?: true

Size: 973 Bytes

Versions: 22

Compression:

Stored size: 973 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 save(*)
      if super
        metadata_node.metadata_uri = described_by # TODO only necessary if the URI was < > before
        metadata_node.save # TODO if changed?
      end
    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 = self.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.0.8 lib/active_fedora/with_metadata.rb
active-fedora-9.1.1 lib/active_fedora/with_metadata.rb
active-fedora-9.1.0 lib/active_fedora/with_metadata.rb
active-fedora-9.1.0.rc1 lib/active_fedora/with_metadata.rb
active-fedora-9.0.6 lib/active_fedora/with_metadata.rb
active-fedora-9.0.5 lib/active_fedora/with_metadata.rb
active-fedora-9.0.4 lib/active_fedora/with_metadata.rb
active-fedora-9.0.3 lib/active_fedora/with_metadata.rb
active-fedora-9.0.2 lib/active_fedora/with_metadata.rb
active-fedora-9.0.1 lib/active_fedora/with_metadata.rb
active-fedora-9.0.0 lib/active_fedora/with_metadata.rb
active-fedora-9.0.0.rc3 lib/active_fedora/with_metadata.rb
active-fedora-9.0.0.rc2 lib/active_fedora/with_metadata.rb
active-fedora-9.0.0.rc1 lib/active_fedora/with_metadata.rb
active-fedora-9.0.0.beta8 lib/active_fedora/with_metadata.rb
active-fedora-9.0.0.beta7 lib/active_fedora/with_metadata.rb
active-fedora-9.0.0.beta6 lib/active_fedora/with_metadata.rb
active-fedora-9.0.0.beta5 lib/active_fedora/with_metadata.rb
active-fedora-9.0.0.beta4 lib/active_fedora/with_metadata.rb
active-fedora-9.0.0.beta3 lib/active_fedora/with_metadata.rb