Sha256: 36dd0ad6f5e4399b359bc14b429106f9809d2da07198a7b2d50f7e0ac26dffcb

Contents?: true

Size: 1.43 KB

Versions: 80

Compression:

Stored size: 1.43 KB

Contents

module ActiveFedora
  class VersionsGraph < ::RDF::Graph
    def all(opts = {})
      versions = fedora_versions
      unless opts[:include_auto_save]
        versions.reject! { |version| version.label =~ /auto/ }
      end
      versions.sort_by { |version| DateTime.parse(version.created) }
    rescue ArgumentError, NoMethodError
      raise ActiveFedora::VersionLacksCreateDate
    end

    delegate :first, to: :all

    delegate :last, to: :all

    def with_label(label)
      all.each do |version|
        return version if version.label == label
      end
    end

    def resources
      query(predicate: ::RDF::Vocab::Fcrepo4.hasVersion)
    end

    private

      class ResourceVersion
        attr_accessor :uri, :label, :created
      end

      def version_from_resource(statement)
        version = ResourceVersion.new
        version.uri = statement.object.to_s.gsub(/\/fcr:metadata$/, "")
        version.label = label_query(statement)
        version.created = created_query(statement)
        version
      end

      def label_query(statement)
        query(subject: statement.object).query(predicate: ::RDF::Vocab::Fcrepo4.hasVersionLabel).first.object.to_s
      end

      def created_query(statement)
        query(subject: statement.object).query(predicate: ::RDF::Vocab::Fcrepo4.created).first.object.to_s
      end

      def fedora_versions
        resources.map { |statement| version_from_resource(statement) }
      end
  end
end

Version data entries

80 entries across 80 versions & 1 rubygems

Version Path
active-fedora-13.3.0 lib/active_fedora/versions_graph.rb
active-fedora-12.2.4 lib/active_fedora/versions_graph.rb
active-fedora-13.2.7 lib/active_fedora/versions_graph.rb
active-fedora-13.2.5 lib/active_fedora/versions_graph.rb
active-fedora-13.2.4 lib/active_fedora/versions_graph.rb
active-fedora-12.2.3 lib/active_fedora/versions_graph.rb
active-fedora-13.2.3 lib/active_fedora/versions_graph.rb
active-fedora-13.2.2 lib/active_fedora/versions_graph.rb
active-fedora-13.2.0 lib/active_fedora/versions_graph.rb
active-fedora-13.1.3 lib/active_fedora/versions_graph.rb
active-fedora-11.5.6 lib/active_fedora/versions_graph.rb
active-fedora-12.2.2 lib/active_fedora/versions_graph.rb
active-fedora-11.2.1 lib/active_fedora/versions_graph.rb
active-fedora-12.2.1 lib/active_fedora/versions_graph.rb
active-fedora-12.0.3 lib/active_fedora/versions_graph.rb
active-fedora-11.5.5 lib/active_fedora/versions_graph.rb
active-fedora-13.1.2 lib/active_fedora/versions_graph.rb
active-fedora-13.1.1 lib/active_fedora/versions_graph.rb
active-fedora-13.1.0 lib/active_fedora/versions_graph.rb
active-fedora-13.0.0 lib/active_fedora/versions_graph.rb