123456789_123456789_123456789_123456789_123456789_

Class: Sprockets::Exporters::ZlibExporter

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
self, Base
Inherits: Sprockets::Exporters::Base
Defined in: lib/sprockets/exporters/zlib_exporter.rb

Overview

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

Class Method Summary

Base - Inherited

.new

Public: Creates new instance.

Instance Attribute Summary

Instance Method Summary

Base - Inherited

#call

Public: Contains logic for writing “exporting” asset to disk.

#setup

Public: Callback that is executed after initialization.

#skip?

Public: Handles logic for skipping exporter and notifying logger.

#write

Public: Yields a file that can be written to with the input.

Constructor Details

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

Instance Method Details

#call

[ GitHub ]

  
# File 'lib/sprockets/exporters/zlib_exporter.rb', line 26

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

#setup

[ GitHub ]

  
# 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

[ GitHub ]

  
# 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