metamaps--metamaps/app/models/attachment.rb

39 lines
935 B
Ruby
Raw Normal View History

2017-01-22 16:28:18 -05:00
# frozen_string_literal: true
2017-01-22 15:23:24 -05:00
class Attachment < ApplicationRecord
belongs_to :attachable, polymorphic: true
has_attached_file :file,
2017-01-22 16:28:18 -05:00
styles: lambda { |a|
if a.instance.image?
{
2017-01-23 13:28:25 -05:00
thumb: 'x128#',
medium: 'x320>'
2017-01-22 16:28:18 -05:00
}
else
{}
end
}
2017-01-22 15:23:24 -05:00
2017-01-23 13:21:44 -05:00
validates_attachment_content_type :file, content_type: Attachable.allowed_types
2017-01-22 15:23:24 -05:00
2017-01-22 16:28:18 -05:00
def image?
2017-01-23 13:28:25 -05:00
Attachable.image_types.include(file.instance.file_content_type)
2017-01-23 13:21:44 -05:00
end
def audio?
2017-01-23 13:28:25 -05:00
Attachable.audio_types.include(file.instance.file_content_type)
2017-01-23 13:21:44 -05:00
end
def text?
2017-01-23 13:28:25 -05:00
Attachable.text_types.include(file.instance.file_content_type)
2017-01-23 13:21:44 -05:00
end
def pdf?
2017-01-23 13:28:25 -05:00
Attachable.pdf_types.include(file.instance.file_content_type)
2017-01-23 13:21:44 -05:00
end
def document?
text? || pdf?
2017-01-22 15:23:24 -05:00
end
end