Class: S3imageoptim::Command

Inherits:
Thor::Group
  • Object
show all
Defined in:
lib/s3imageoptim/command.rb

Instance Method Summary collapse

Instance Method Details

#compressObject



21
22
23
24
25
26
27
28
29
30
# 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

#getObject



11
12
13
14
15
16
17
18
19
# 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

#putObject



32
33
34
35
36
# 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

#removeObject



38
39
40
# File 'lib/s3imageoptim/command.rb', line 38

def remove
  FileUtils.remove_entry(tmpdir)
end