sutty/app/models/metadata_image.rb

27 lines
531 B
Ruby
Raw Normal View History

2019-08-06 17:54:17 +00:00
# frozen_string_literal: true
# Define un campo de imagen
2019-11-07 16:08:14 +00:00
class MetadataImage < MetadataFile
2019-08-22 19:13:21 +00:00
def validate
super
2019-08-23 18:24:41 +00:00
errors << I18n.t('metadata.image.not_an_image') unless image?
2019-08-22 19:13:21 +00:00
errors.compact!
errors.empty?
end
2019-08-23 18:24:41 +00:00
# Determina si es una imagen antes de subirla
def image?
if value['path'].is_a? ActionDispatch::Http::UploadedFile
`file --mime-type "#{value['path'].tempfile.path}"`
.split(' ')
.last
.chomp
.starts_with? 'image/'
else
true
end
end
2019-08-06 17:54:17 +00:00
end