Module: ActiveFedora::Versionable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/active_fedora/versionable.rb
Instance Method Summary collapse
- #create_version ⇒ Object
-
#has_versions? ⇒ Boolean
Queries Fedora to figure out if there are versions for the resource.
- #model_type ⇒ Object
- #restore_version(label) ⇒ Object
-
#versions(reload = false) ⇒ Object
Returns an array of ActiveFedora::VersionsGraph::ResourceVersion objects.
Instance Method Details
#create_version ⇒ Object
31 32 33 34 35 |
# File 'lib/active_fedora/versionable.rb', line 31 def create_version resp = ActiveFedora.fedora.connection.post(versions_uri, nil, slug: version_name) @versions = nil resp.success? end |
#has_versions? ⇒ Boolean
Queries Fedora to figure out if there are versions for the resource.
38 39 40 41 42 43 |
# File 'lib/active_fedora/versionable.rb', line 38 def has_versions? ActiveFedora.fedora.connection.head(versions_uri) true rescue Ldp::NotFound false end |
#model_type ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/active_fedora/versionable.rb', line 9 def model_type if respond_to?(:metadata) .ldp_source.graph.query(predicate: ::RDF.type).objects else resource.query(subject: resource.rdf_subject, predicate: ::RDF.type).objects end end |
#restore_version(label) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/active_fedora/versionable.rb', line 45 def restore_version(label) resp = ActiveFedora.fedora.connection.patch(versions.with_label(label).uri, nil) @versions = nil reload refresh_attributes if respond_to?("refresh_attributes") resp.success? end |
#versions(reload = false) ⇒ Object
Returns an array of ActiveFedora::VersionsGraph::ResourceVersion objects. Excludes auto-snapshot versions from Fedora.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_fedora/versionable.rb', line 19 def versions(reload = false) response = versions_request return ActiveFedora::VersionsGraph.new unless response if reload @versions = ActiveFedora::VersionsGraph.new << versions_request.reader else @versions ||= ActiveFedora::VersionsGraph.new << versions_request.reader end end |