-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #882 from pulibrary/start_canvas
Add Start Canvas
- Loading branch information
Showing
4 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
class ManifestBuilder | ||
class StartCanvasBuilder | ||
attr_reader :resource, :canvas_builder | ||
|
||
# @param [Valhalla::Resource] resource the Resource being viewed | ||
def initialize(resource, canvas_builder:) | ||
@resource = resource | ||
@canvas_builder = canvas_builder | ||
end | ||
|
||
def apply(manifest) | ||
return manifest unless start_canvas_id && file_set | ||
manifest['startCanvas'] = path | ||
manifest | ||
end | ||
|
||
private | ||
|
||
def path | ||
canvas_builder.new(file_set, resource).path | ||
end | ||
|
||
def file_set | ||
@file_set ||= query_service.find_by(id: start_canvas_id) | ||
rescue Valkyrie::Persistence::ObjectNotFoundError | ||
nil | ||
end | ||
|
||
def query_service | ||
Valkyrie.config.metadata_adapter.query_service | ||
end | ||
|
||
def start_canvas_id | ||
Array.wrap(resource.resource.try(:start_canvas)).first | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters