Skip to content

Commit

Permalink
Merge pull request #344 from sul-dlss/consistency-oy
Browse files Browse the repository at this point in the history
refactoring: consistently use "item" in ItemQueryService
  • Loading branch information
mjgiarlo committed Aug 27, 2019
2 parents ba2a5ef + 3b3c5aa commit efe80f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions app/services/item_query_service.rb
@@ -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
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -97,7 +97,7 @@
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# config.profile_examples = 10

# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
Expand Down

0 comments on commit efe80f3

Please sign in to comment.