Class: RubyArchive::Handler

Inherits:
Object show all
Defined in:
lib/ruby_archive/handler.rb,
lib/ruby_archive.rb

Overview

RubyArchive::Handler

Direct Known Subclasses

RubyArchive::Handlers::ZipHandler

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ Handler

Initialize a handler object for the location given. The default implementation raises a NotImplementedError.

Your implementation needs to set @name to identify the archive

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/ruby_archive/handler.rb', line 24

def initialize location
  raise NotImplementedError, "Cannot initialize a handler of class #{self.class}"
end

Instance Attribute Details

#nameObject (readonly)

reader for @name, which should be set in initialize



49
50
51
# File 'lib/ruby_archive/handler.rb', line 49

def name
  @name
end

Class Method Details

.handles?(location) ⇒ Boolean

Should return true if the class can handle the given location as an archive. Returns false otherwise. The default implementation always returns false, this must be overridden in your subclasses.

This method must NOT raise an exception.

Returns:

  • (Boolean)


9
10
11
# File 'lib/ruby_archive/handler.rb', line 9

def self.handles? location
  false
end

.normalize_path(location) ⇒ Object

Should return a normalized version of the location specified. File.expand_path works well in many cases, and is provided as the default.



16
17
18
# File 'lib/ruby_archive/handler.rb', line 16

def self.normalize_path location
  File.expand_path(location)
end

Instance Method Details

#closeObject

Close the handler. This will be executed when RubyArchive::close_all_archives is executed, or at_exit

Should always return nil



32
33
34
# File 'lib/ruby_archive/handler.rb', line 32

def close
  nil
end

#dirObject

Should return a Dir-like object for the archive (optional) Should return nil if not supported.



44
45
46
# File 'lib/ruby_archive/handler.rb', line 44

def dir
  nil
end

#fileObject

Should return a File-like object for the archive. The default implementation raises a NotImplentedError, must be overridden.

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/ruby_archive/handler.rb', line 38

def file
  raise NotImplementedError, "Cannot retrieve a file object for class #{self.class}"
end

#inspectObject



51
52
53
# File 'lib/ruby_archive/handler.rb', line 51

def inspect
  "<#{self.class}:#{self.name}>"
end