Class: Sprockets::Exporters::ZlibExporter

Inherits:
Base
  • Object
show all
Defined in:
lib/sprockets/exporters/zlib_exporter.rb

Overview

Generates a ‘.gz` file using the zlib algorithm built into Ruby’s standard library.

Direct Known Subclasses

ZopfliExporter

Instance Attribute Summary

Attributes inherited from Base

#asset, #directory, #environment, #target

Instance Method Summary collapse

Methods inherited from Base

#initialize, #write

Constructor Details

This class inherits a constructor from Sprockets::Exporters::Base

Instance Method Details

#callObject



26
27
28
29
30
# File 'lib/sprockets/exporters/zlib_exporter.rb', line 26

def call
  write(@gzip_target) do |file|
    @gzip.compress(file, target)
  end
end

#setupObject



9
10
11
12
# File 'lib/sprockets/exporters/zlib_exporter.rb', line 9

def setup
  @gzip_target = "#{ target }.gz"
  @gzip = Sprockets::Utils::Gzip.new(asset, archiver: Utils::Gzip::ZlibArchiver)
end

#skip?(logger) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sprockets/exporters/zlib_exporter.rb', line 14

def skip?(logger)
  return true if environment.skip_gzip?
  return true if @gzip.cannot_compress?
  if ::File.exist?(@gzip_target)
    logger.debug "Skipping #{ @gzip_target }, already exists"
    true
  else
    logger.info "Writing #{ @gzip_target }"
    false
  end
end