class S3imageoptim::Command
Public Instance Methods
compress()
click to toggle source
# File lib/s3imageoptim/command.rb, line 21 def compress ImageOptim.new( svgo: false, pngout: false, jpegoptim: { allow_lossy: true, max_quality: 80 } ).optimize_images!(local_files) end
get()
click to toggle source
# File lib/s3imageoptim/command.rb, line 11 def get s3cmd("get --exclude '*' --rinclude '\.(#{extensions("|")})$' --recursive #{bucket} #{tmpdir}") do |error| abort("An error ocurred while getting the files: #{error}") end if local_files.empty? abort("No images were found in the bucket") end end
put()
click to toggle source
# File lib/s3imageoptim/command.rb, line 32 def put s3cmd("sync --acl-#{options[:acl]} #{tmpdir}/ #{bucket}") do |error| abort("An error ocurred while putting the files: #{error}") end end
remove()
click to toggle source
# File lib/s3imageoptim/command.rb, line 38 def remove FileUtils.remove_entry(tmpdir) end
Private Instance Methods
extensions(separator)
click to toggle source
# File lib/s3imageoptim/command.rb, line 47 def extensions(separator) %w{jpg jpeg png}.join(separator) end
local_files()
click to toggle source
# File lib/s3imageoptim/command.rb, line 43 def local_files Dir.glob(File.join(tmpdir, "**", "*.{#{extensions(",")}}")) end
s3cmd(args, &failure_block)
click to toggle source
# File lib/s3imageoptim/command.rb, line 55 def s3cmd(args, &failure_block) Open3.popen3("s3cmd #{args}") do |stdin, stdout, stderr, thread| thread.value.success? ? stdout.read : failure_block.call(stderr.read) end end
tmpdir()
click to toggle source
# File lib/s3imageoptim/command.rb, line 51 def tmpdir @tmpdir ||= Dir.mktmpdir end