Class: Hyrax::VersioningService
- Inherits:
-
Object
- Object
- Hyrax::VersioningService
- Defined in:
- app/services/hyrax/versioning_service.rb
Overview
Provides methods for dealing with versions of files across both ActiveFedora and Valkyrie.
Note that many of the methods pertaining to version creation are currently implemented as static methods.
Instance Attribute Summary collapse
- #resource ⇒ ActiveFedora::File | Hyrax::FileMetadata | NilClass
-
#storage_adapter ⇒ Object
readonly
Returns the value of attribute storage_adapter.
Class Method Summary collapse
-
.create(content, user = nil) ⇒ Object
Make a version and record the version committer.
- .latest_version_of(file) ⇒ Object
-
.record_committer(content, user_key) ⇒ Object
Record the version committer of the last version.
- .versioned_file_id(file) ⇒ Object
Instance Method Summary collapse
-
#initialize(resource:, storage_adapter: Hyrax.storage_adapter) ⇒ VersioningService
constructor
A new instance of VersioningService.
-
#latest_version ⇒ Object
Returns the latest version of the file associated with this Hyrax::VersioningService.
-
#versioned_file_id ⇒ Object
Returns the file ID of the latest version of the file associated with this Hyrax::VersioningService, or the ID of the file resource itself if no latest version is defined.
-
#versions ⇒ Object
Returns an array of versions for the resource associated with this Hyrax::VersioningService.
Constructor Details
#initialize(resource:, storage_adapter: Hyrax.storage_adapter) ⇒ VersioningService
Returns a new instance of VersioningService.
23 24 25 26 |
# File 'app/services/hyrax/versioning_service.rb', line 23 def initialize(resource:, storage_adapter: Hyrax.storage_adapter) @storage_adapter = storage_adapter self.resource = resource end |
Instance Attribute Details
#resource ⇒ ActiveFedora::File | Hyrax::FileMetadata | NilClass
14 15 16 |
# File 'app/services/hyrax/versioning_service.rb', line 14 def resource @resource end |
#storage_adapter ⇒ Object (readonly)
Returns the value of attribute storage_adapter.
19 20 21 |
# File 'app/services/hyrax/versioning_service.rb', line 19 def storage_adapter @storage_adapter end |
Class Method Details
.create(content, user = nil) ⇒ Object
Make a version and record the version committer
82 83 84 85 |
# File 'app/services/hyrax/versioning_service.rb', line 82 def create(content, user = nil) use_valkyrie = content.is_a? Hyrax::FileMetadata perform_create(content, user, use_valkyrie) end |
.latest_version_of(file) ⇒ Object
88 89 90 |
# File 'app/services/hyrax/versioning_service.rb', line 88 def latest_version_of(file) Hyrax::VersioningService.new(resource: file).latest_version end |
.record_committer(content, user_key) ⇒ Object
Record the version committer of the last version
100 101 102 103 104 105 106 |
# File 'app/services/hyrax/versioning_service.rb', line 100 def 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? version_id = content.is_a?(Hyrax::FileMetadata) ? version.id.to_s : version.uri Hyrax::VersionCommitter.create(version_id: version_id, committer_login: user_key) end |
.versioned_file_id(file) ⇒ Object
93 94 95 |
# File 'app/services/hyrax/versioning_service.rb', line 93 def versioned_file_id(file) Hyrax::VersioningService.new(resource: file).versioned_file_id end |
Instance Method Details
#latest_version ⇒ Object
Returns the latest version of the file associated with this Hyrax::VersioningService.
51 52 53 |
# File 'app/services/hyrax/versioning_service.rb', line 51 def latest_version versions.last end |
#versioned_file_id ⇒ Object
Returns the file ID of the latest version of the file associated with this Hyrax::VersioningService, or the ID of the file resource itself if no latest version is defined.
If the resource is nil, this method returns an empty string.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/services/hyrax/versioning_service.rb', line 61 def versioned_file_id latest = latest_version if latest if latest.respond_to?(:id) latest.id else Hyrax.config.translate_uri_to_id.call(latest.uri) end elsif resource.nil? "" elsif resource.is_a?(Hyrax::FileMetadata) resource.file_identifier else resource.id end end |
#versions ⇒ Object
Returns an array of versions for the resource associated with this Hyrax::VersioningService.
If the resource is nil, or if it is a Hyrax::FileMetadata and versioning is not supported in the storage adapter, an empty array will be returned.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/services/hyrax/versioning_service.rb', line 34 def versions if resource.nil? [] elsif resource.is_a?(Hyrax::FileMetadata) if storage_adapter.try(:"supports?", :versions) storage_adapter.find_versions(id: resource.file_identifier).to_a else [] end else resource.versions.all.to_a end end |