module PdfCover
This module provides methods for CarrierWave::Uploader::Base subclasses and for ActiveRecord models that want to include attachments to simplify the generation of JPEG images from the first page of a PDF file that is uploaded by the users. Include this module in your class and check the `ClassMethods` documentation that corresponds to your attachments managing library in this same file.
Constants
- VERSION
Public Class Methods
included(base)
click to toggle source
# File lib/pdf_cover.rb, line 72 def included(base) if carrierwave_defined?(base) base.extend ClassMethods::CarrierWave elsif paperclip_defined? require "paperclip/pdf_cover_processor" base.extend ClassMethods::Paperclip else fail "#{base} is not a CarrierWave::Uploader and Paperclip is not defined ¯\\_(ツ)_/¯" end end
Private Class Methods
carrierwave_defined?(base)
click to toggle source
# File lib/pdf_cover.rb, line 85 def carrierwave_defined?(base) defined?(CarrierWave::Uploader::Base) && base.ancestors.include?(CarrierWave::Uploader::Base) end
paperclip_defined?()
click to toggle source
# File lib/pdf_cover.rb, line 89 def paperclip_defined? defined?(Paperclip) end
Public Instance Methods
enforce_content_type(content_type)
click to toggle source
# File lib/pdf_cover.rb, line 101 def enforce_content_type(content_type) file.content_type = content_type end
pdf_cover(quality, resolution)
click to toggle source
This is the method used by the CarrierWave processor mechanism
# File lib/pdf_cover.rb, line 95 def pdf_cover(quality, resolution) options = { quality: quality, resolution: resolution }.compact converted_file = PdfCover::Converter.new(file, options).converted_file FileUtils.cp(converted_file, current_path) end