Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extracting common uploader logic to parent class

  • Loading branch information...
commit 14b3721d2b2fad36ed0453d09e7a57fd9f586b1a 1 parent e3f0758
@rwdaigle authored
View
3  lib/pdf_archive.rb
@@ -47,6 +47,7 @@ def self.root
end
# require pdf uploader, document model, and process pdf job
+require 'uploader'
require 'pdf_uploader'
require 'preview_store'
require 'document'
@@ -71,4 +72,4 @@ def self.root
get '/search' do
@documents = Document.search(params['q'])
erb :home
-end
+end
View
19 lib/pdf_uploader.rb
@@ -1,20 +1,5 @@
-class PdfUploader < CarrierWave::Uploader::Base
+class PdfUploader < Uploader
Grim::WIDTH = 100
- storage PdfArchive.environment == "production" ? :fog : :file
-
- def cache_dir
- "#{PdfArchive.root}/tmp/cache/#{model.id}"
- end
-
- def store_dir
- if PdfArchive.environment == 'test'
- "#{PdfArchive.root}/tmp/documents/#{model.id}"
- elsif PdfArchive.environment == 'production'
- "documents/#{model.id}"
- else
- "#{PdfArchive.root}/public/documents/#{model.id}"
- end
- end
def grim
cache_stored_file! unless cached?
@@ -27,4 +12,4 @@ def create_preview
grim[0].save(output_path)
return output_path
end
-end
+end
View
19 lib/preview_store.rb
@@ -1,17 +1,2 @@
-class PreviewStore < CarrierWave::Uploader::Base
- storage PdfArchive.environment == "production" ? :fog : :file
-
- def cache_dir
- "#{PdfArchive.root}/tmp/cache/#{model.id}"
- end
-
- def store_dir
- if PdfArchive.environment == 'test'
- "#{PdfArchive.root}/tmp/documents/#{model.id}"
- elsif PdfArchive.environment == 'production'
- "documents/#{model.id}"
- else
- "#{PdfArchive.root}/public/documents/#{model.id}"
- end
- end
-end
+class PreviewStore < Uploader
+end
View
18 lib/uploader.rb
@@ -0,0 +1,18 @@
+class Uploader < CarrierWave::Uploader::Base
+ storage PdfArchive.environment == "production" ? :fog : :file
+
+ def cache_dir
+ "#{PdfArchive.root}/tmp/cache/#{model.id}"
+ end
+
+ def store_dir
+ if PdfArchive.environment == 'test'
+ "#{PdfArchive.root}/tmp/documents/#{model.id}"
+ elsif PdfArchive.environment == 'production'
+ "documents/#{model.id}"
+ else
+ "#{PdfArchive.root}/public/documents/#{model.id}"
+ end
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.