class RapperLite::Compressors::Compressor
Base class for a compression handler.
Attributes
extensions[RW]
Public Class Methods
compress( file_path, opts={} )
click to toggle source
Compress a file. Raises an error if it doesn’t know how to compress a file with the given file’s file extension.
# File lib/rapper_lite/compressors.rb, line 27 def compress( file_path, opts={} ) unless compressor = @extensions[File.extname( file_path )] raise "RapperLite doesn't know how to compress #{file_path}" end compressor.do_compress( file_path, opts ) end
Protected Class Methods
do_compress( file_path )
click to toggle source
# File lib/rapper_lite/compressors.rb, line 45 def do_compress( file_path ) raise NotImplementedError end
read_file( file_path )
click to toggle source
# File lib/rapper_lite/compressors.rb, line 49 def read_file( file_path ) File.read( file_path ) end
register( extension )
click to toggle source
Register ‘self` as a file compressor for the given file extension.
# File lib/rapper_lite/compressors.rb, line 40 def register( extension ) superclass.extensions ||= {} superclass.extensions[extension] = self end
writable_file( file_path )
click to toggle source
Get a writable file instance with 0644 permissions.
# File lib/rapper_lite/compressors.rb, line 54 def writable_file( file_path ) File.new( file_path, 'w', 0644 ) end