Class: Grably::ZipJob

Inherits:
Object
  • Object
show all
Includes:
Job
Defined in:
lib/grably/jobs/zip/zip.rb

Overview

TBD

Constant Summary collapse

OPTIONS =
{
  compression_level: ->(value) { "-r#{value}" }
}.freeze

Instance Method Summary collapse

Methods included from Job

included, jobs

Instance Method Details

#buildObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/grably/jobs/zip/zip.rb', line 20

def build
  if files.empty?
    warn 'No files to zip'
    return []
  end

  log "Zipping #{files.size} files into #{File.basename(dst)}"

  src_dir = job_dir('src')
  ln(files, src_dir)
  zip(src_dir)
end

#cflagsObject



40
41
42
43
44
# File 'lib/grably/jobs/zip/zip.rb', line 40

def cflags
  OPTIONS
    .select { |k, _v| meta.key?(k) }
    .map { |k, _v| OPTIONS[k].call(meta[k]) }
end

#setup(srcs, dst, meta = {}) ⇒ Object



14
15
16
17
18
# File 'lib/grably/jobs/zip/zip.rb', line 14

def setup(srcs, dst, meta = {})
  @files = srcs
  @dst = dst
  @meta = meta
end

#zip(dir) ⇒ Object



33
34
35
36
37
38
# File 'lib/grably/jobs/zip/zip.rb', line 33

def zip(dir)
  Dir.chdir(dir) do
    ['zip', cflags, File.join('..', File.basename(dst)), '.'].run
  end
  Product.new(job_dir(File.basename(dst)), dst, meta)
end