Class: Hyrax::VersioningService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/versioning_service.rb

Class Method Summary collapse

Class Method Details

.create(content, user = nil) ⇒ Object

Make a version and record the version committer

Parameters:

  • content (ActiveFedora::File)
  • user (User, String) (defaults to: nil)

6
7
8
9
# File 'app/services/hyrax/versioning_service.rb', line 6

def self.create(content, user = nil)
  content.create_version
  record_committer(content, user) if user
end

.latest_version_of(file) ⇒ Object

Parameters:

  • file (ActiveFedora::File)

12
13
14
# File 'app/services/hyrax/versioning_service.rb', line 12

def self.latest_version_of(file)
  file.versions.last
end

.record_committer(content, user_key) ⇒ Object

Record the version committer of the last version

Parameters:

  • content (ActiveFedora::File)
  • user_key (User, String)

19
20
21
22
23
24
# File 'app/services/hyrax/versioning_service.rb', line 19

def self.record_committer(content, user_key)
  user_key = user_key.user_key if user_key.respond_to?(:user_key)
  version = latest_version_of(content)
  return if version.nil?
  VersionCommitter.create(version_id: version.uri, committer_login: user_key)
end

.versioned_file_id(file) ⇒ Object

Parameters:

  • content (ActiveFedora::File | Hyrax::FileMetadata)

27
28
29
30
31
32
33
# File 'app/services/hyrax/versioning_service.rb', line 27

def self.versioned_file_id(file)
  versions = file.versions.all

  return ActiveFedora::Base.uri_to_id(versions.last.uri) if versions.present?

  file.id
end