Module: ActiveFedora::Versionable

Extended by:
ActiveSupport::Concern
Included in:
Base, File
Defined in:
lib/active_fedora/versionable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#create_versionObject


33
34
35
36
37
# File 'lib/active_fedora/versionable.rb', line 33

def create_version
  resp = ActiveFedora.fedora.connection.post(versions_uri, nil, {slug: version_name})
  @versions = nil
  resp.success?
end

#has_versions?Boolean

This method does not rely on the internal versionable flag of the object, instead it queries Fedora directly to figure out if there are versions for the resource.

Returns:

  • (Boolean)

41
42
43
44
45
46
# File 'lib/active_fedora/versionable.rb', line 41

def has_versions?
  ActiveFedora.fedora.connection.head(versions_uri) 
  true
rescue Ldp::NotFound
  false
end

#model_typeObject


15
16
17
18
19
20
21
# File 'lib/active_fedora/versionable.rb', line 15

def model_type
  if self.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


48
49
50
51
52
53
54
# File 'lib/active_fedora/versionable.rb', line 48

def restore_version label
  resp = ActiveFedora.fedora.connection.patch(versions.with_label(label).uri, nil)
  @versions = nil
  reload
  refresh_attributes if self.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.


25
26
27
28
29
30
31
# File 'lib/active_fedora/versionable.rb', line 25

def versions(reload=false)
  if reload
    @versions = ActiveFedora::VersionsGraph.new << ::RDF::Reader.for(:ttl).new(versions_request)
  else
    @versions ||= ActiveFedora::VersionsGraph.new << ::RDF::Reader.for(:ttl).new(versions_request)     
  end
end