Skip to content

Commit

Permalink
Refactor ThumbnailPathService
Browse files Browse the repository at this point in the history
This makes it easier to override parts. Also added more documentation
  • Loading branch information
jcoyne committed Jun 9, 2016
1 parent 2c01c61 commit e6855ee
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions app/services/curation_concerns/thumbnail_path_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,47 @@ def call(object)
if thumb.audio?
audio_image
elsif thumbnail?(thumb)
Rails.application.routes.url_helpers.download_path(object.thumbnail_id, file: 'thumbnail')
thumbnail_path(thumb)
else
default_image
end
end

def fetch_thumbnail(object)
return object if object.thumbnail_id == object.id
::ActiveFedora::Base.find(object.thumbnail_id)
rescue ActiveFedora::ObjectNotFoundError
Rails.logger.error("Couldn't find thumbnail #{object.thumbnail_id} for #{object.id}")
nil
end
protected

def default_image
ActionController::Base.helpers.image_path 'default.png'
end
def fetch_thumbnail(object)
return object if object.thumbnail_id == object.id
::ActiveFedora::Base.find(object.thumbnail_id)
rescue ActiveFedora::ObjectNotFoundError
Rails.logger.error("Couldn't find thumbnail #{object.thumbnail_id} for #{object.id}")
nil
end

def audio_image
ActionController::Base.helpers.image_path 'audio.png'
end
# @return the network path to the thumbnail
# @param [FileSet] thumbnail the object that is the thumbnail
def thumbnail_path(thumbnail)
Rails.application.routes.url_helpers.download_path(thumbnail.id,
file: 'thumbnail')
end

# @return true if there a file on disk for this object, otherwise false
def thumbnail?(thumb)
File.exist?(thumbnail_filepath(thumb))
end
def default_image
ActionController::Base.helpers.image_path 'default.png'
end

def thumbnail_filepath(thumb)
CurationConcerns::DerivativePath.derivative_path_for_reference(thumb, 'thumbnail')
end
def audio_image
ActionController::Base.helpers.image_path 'audio.png'
end

# @return true if there a file on disk for this object, otherwise false
# @param [FileSet] thumbnail the object that is the thumbnail
def thumbnail?(thumb)
File.exist?(thumbnail_filepath(thumb))
end

# @param [FileSet] thumbnail the object that is the thumbnail
def thumbnail_filepath(thumb)
CurationConcerns::DerivativePath.derivative_path_for_reference(thumb, 'thumbnail')
end
end
end
end

0 comments on commit e6855ee

Please sign in to comment.