Skip to content

Instantly share code, notes, and snippets.

@zaeleus
Created May 5, 2016 23:07
Show Gist options
  • Save zaeleus/5784e0b966555c5d008ec534ad7b1501 to your computer and use it in GitHub Desktop.
Save zaeleus/5784e0b966555c5d008ec534ad7b1501 to your computer and use it in GitHub Desktop.
require 'shrine'
require 'shrine/storage/memory'
Shrine.storages = {
cache: Shrine::Storage::Memory.new,
store: Shrine::Storage::Memory.new
}
class DocumentUploader < Shrine
plugin :determine_mime_type
plugin :validation_helpers
Attacher.validate do
validate_mime_type_inclusion ['image/jpeg']
end
end
class Document
include DocumentUploader[:attachment]
attr_accessor :attachment_data
end
document = Document.new
document.attachment = File.open('-image.jpg')
p document.attachment_attacher.errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment