Class: Plotline::Import::Handlers::ImageFile
- Inherits:
-
Base
- Object
- Base
- Plotline::Import::Handlers::ImageFile
show all
- Defined in:
- lib/plotline/import/handlers/image_file.rb
Constant Summary
collapse
- IMAGE_EXTENSIONS =
%w(jpg jpeg png gif bmp tiff).freeze
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#import(filename) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/plotline/import/handlers/image_file.rb', line 11
def import(filename)
log "\e[34mImporting:\e[0m #{filename}"
if !File.exists?(filename)
log "FILE REMOVED"
return
end
dst = filename.gsub(@runner.source_dir, @runner.uploads_dir)
FileUtils.mkdir_p(File.dirname(dst))
FileUtils.cp(filename, dst)
file = dst.gsub(@runner.public_dir, '')
image = Plotline::Image.find_or_initialize_by(image: file)
return if image.persisted? && File.size(dst) == image.file_size
image.save!
end
|
#supported_file?(filename) ⇒ Boolean
7
8
9
|
# File 'lib/plotline/import/handlers/image_file.rb', line 7
def supported_file?(filename)
IMAGE_EXTENSIONS.include?(File.extname(filename).gsub('.', ''))
end
|