Module: RubyArchive
- Defined in:
- lib/ruby_archive.rb,
lib/ruby_archive/handler.rb
Defined Under Namespace
Modules: Handlers Classes: Handler
Class Method Summary collapse
-
.add_handler_class(handler_class) ⇒ Object
Adds an archive handler to the list used.
- .close_all_archives ⇒ Object
-
.find_handler_class(location) ⇒ Object
Finds the appropriate
RubyArchive::Handler
subclass for a given location. -
.get(location, autoload = true) ⇒ Object
Retrieves an archive from the loaded_archives cache, or automatically loads the archive.
-
.load(location) ⇒ Object
Loads the specified archive location.
Class Method Details
.add_handler_class(handler_class) ⇒ Object
Adds an archive handler to the list used. Provided handler must be a subclass of RubyArchive::Handler
17 18 19 20 21 22 23 |
# File 'lib/ruby_archive.rb', line 17 def add_handler_class handler_class unless (handler_class.is_a? Class) && (handler_class <= RubyArchive::Handler) raise TypeError, "#{handler_class} is not a RubyArchive::Handler" end @@archive_handlers << handler_class true end |
.close_all_archives ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/ruby_archive.rb', line 64 def close_all_archives @@loaded_archives.each_value do |archive| archive.close end @@loaded_archives.clear true end |
.find_handler_class(location) ⇒ Object
Finds the appropriate RubyArchive::Handler
subclass for a given location. Returns nil if no supported handler found.
28 29 30 31 32 33 |
# File 'lib/ruby_archive.rb', line 28 def find_handler_class location @@archive_handlers.each do |h| return h if h.handles?(location) end return nil end |
.get(location, autoload = true) ⇒ Object
Retrieves an archive from the loaded_archives cache, or automatically loads the archive. Returns the archive on success. Returns nil if archive is not available and autoload is false. Raises LoadError
if autoload is attempted and fails.
41 42 43 44 45 46 47 48 |
# File 'lib/ruby_archive.rb', line 41 def get location, autoload=true @@archive_handlers.each do |h| normalized = h.normalize_path(location) return @@loaded_archives[normalized] if @@loaded_archives.has_key?(normalized) end return load(location) if autoload nil end |
.load(location) ⇒ Object
Loads the specified archive location. Returns the handler object on success. Raises LoadError
if no handler can be found or it does not exist. May also pass exceptions passed along by creating the handler.
54 55 56 57 58 59 60 61 |
# File 'lib/ruby_archive.rb', line 54 def load location handler_class = find_handler_class(location) if handler_class.nil? raise LoadError, "No handler found or does not exist for archive -- #{location}" end archive = handler_class.new(location) @@loaded_archives[archive.name] = archive end |