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 #344 from sul-dlss/consistency-oy
refactoring: consistently use "item" in ItemQueryService
- Loading branch information
Showing
2 changed files
with
15 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
# Responsible for retrieving information based on the given work (Dor::Item). | ||
# Responsible for retrieving information based on the given Dor::Item. | ||
class ItemQueryService | ||
# @param [String] id - The id of the work | ||
# @param [#exists?, #find] work_relation - How we will query some of the related information | ||
def initialize(id:, work_relation: default_work_relation) | ||
# @param [String] id - The id of the item | ||
# @param [#exists?, #find] item_relation - How we will query some of the related information | ||
def initialize(id:, item_relation: default_item_relation) | ||
@id = id | ||
@work_relation = work_relation | ||
@item_relation = item_relation | ||
end | ||
|
||
delegate :allows_modification?, to: :work | ||
delegate :allows_modification?, to: :item | ||
|
||
# @raises [RuntimeError] if the item is not modifiable | ||
def self.find_modifiable_item(druid) | ||
query_service = ItemQueryService.new(id: druid) | ||
query_service.work do |work| | ||
raise "Item #{work.pid} is not open for modification" unless query_service.allows_modification? | ||
query_service.item do |item| | ||
raise "Item #{item.pid} is not open for modification" unless query_service.allows_modification? | ||
end | ||
end | ||
|
||
def work(&block) | ||
@work ||= work_relation.find(id) | ||
return @work unless block_given? | ||
def item(&block) | ||
@item ||= item_relation.find(id) | ||
return @item unless block_given? | ||
|
||
@work.tap(&block) | ||
@item.tap(&block) | ||
end | ||
|
||
private | ||
|
||
attr_reader :id, :work_relation | ||
attr_reader :id, :item_relation | ||
|
||
def default_work_relation | ||
def default_item_relation | ||
Dor::Item | ||
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