Class: ZipContainer::Container
- Inherits:
-
Object
- Object
- ZipContainer::Container
- Includes:
- ManagedEntries, ReservedNames
- Defined in:
- lib/zip-container/container.rb
Overview
The superclass of anything that represents a Zip Container. That representation could be as a Zip file (most commonly), as a directory or something else.
Constant Summary collapse
- MIMETYPE_FILE =
:stopdoc: The reserved mimetype file name for standard ZipContainers.
'mimetype'.freeze
Instance Attribute Summary collapse
-
#mimetype ⇒ Object
readonly
The mime-type of this ZipContainer.
Class Method Summary collapse
-
.open(filename) ⇒ Object
:call-seq: open(filename) -> container open(filename) {|container| …}.
-
.verify(filename) ⇒ Object
:call-seq: verify(filename) -> Array.
-
.verify!(filename) ⇒ Object
:call-seq: verify!(filename).
-
.verify?(filename) ⇒ Boolean
:call-seq: verify?(filename) -> boolean.
Instance Method Summary collapse
-
#initialize(location) ⇒ Container
constructor
A new instance of Container.
-
#verify ⇒ Object
:call-seq: verify -> Array.
-
#verify! ⇒ Object
:call-seq: verify!.
-
#verify? ⇒ Boolean
:call-seq: verify? -> true or false.
Methods included from ManagedEntries
#hidden_directory?, #hidden_entry?, #hidden_file?, #managed_directories, #managed_directory?, #managed_directory_names, #managed_entries, #managed_entry?, #managed_entry_names, #managed_file?, #managed_file_names, #managed_files, #verify_managed_entries, #verify_managed_entries!
Methods included from Util
Methods included from ReservedNames
#reserved_entry?, #reserved_names
Constructor Details
#initialize(location) ⇒ Container
Returns a new instance of Container.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/zip-container/container.rb', line 53 def initialize(location) @container = open_container(location) @mimetype_error = verify_mimetype @mimetype = read_mimetype if @mimetype_error.nil? # Reserved entry names. Just the mimetype file by default. register_reserved_name(MIMETYPE_FILE) # Initialize the managed entry tables. initialize_managed_entries end |
Instance Attribute Details
#mimetype ⇒ Object (readonly)
The mime-type of this ZipContainer.
47 48 49 |
# File 'lib/zip-container/container.rb', line 47 def mimetype @mimetype end |
Class Method Details
.open(filename) ⇒ Object
:call-seq:
open(filename) -> container
open(filename) {|container| ...}
Open an existing ZipContainer. It will be checked for conformance upon first access.
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/zip-container/container.rb', line 73 def self.open(filename) c = new(filename) if block_given? begin yield c ensure c.close end end c end |
.verify(filename) ⇒ Object
:call-seq:
verify(filename) -> Array
Verify that the specified ZipContainer conforms to the specification. This method returns a list of problems with the container.
Exceptions are still raised for fundamental file system errors.
94 95 96 |
# File 'lib/zip-container/container.rb', line 94 def self.verify(filename) new(filename).verify end |
.verify!(filename) ⇒ Object
:call-seq:
verify!(filename)
Verify that the specified ZipContainer conforms to the specification. This method raises exceptions when errors are found or if there is something fundamental wrong with the container itself (e.g. it cannot be found).
117 118 119 |
# File 'lib/zip-container/container.rb', line 117 def self.verify!(filename) new(filename).verify! end |
.verify?(filename) ⇒ Boolean
:call-seq:
verify?(filename) -> boolean
Verify that the specified ZipContainer conforms to the specification. This method returns false
if there are any problems at all with the container.
Exceptions are still raised for fundamental file system errors.
106 107 108 |
# File 'lib/zip-container/container.rb', line 106 def self.verify?(filename) new(filename).verify? end |
Instance Method Details
#verify ⇒ Object
:call-seq:
verify -> Array
Verify the contents of this ZipContainer file. All managed files and directories are checked to make sure that they exist, if required.
126 127 128 |
# File 'lib/zip-container/container.rb', line 126 def verify @mimetype_error.nil? ? verify_managed_entries : [@mimetype_error] end |
#verify! ⇒ Object
:call-seq:
verify!
Verify the contents of this ZipContainer file. All managed files and directories are checked to make sure that they exist, if required.
This method raises a MalformedContainerError if there are any problems with the container.
150 151 152 153 154 |
# File 'lib/zip-container/container.rb', line 150 def verify! raise MalformedContainerError, @mimetype_error unless @mimetype_error.nil? verify_managed_entries! end |
#verify? ⇒ Boolean
:call-seq:
verify? -> true or false
Verify the contents of this ZipContainer file. All managed files and directories are checked to make sure that they exist, if required.
This method returns false
if there are any problems at all with the container.
138 139 140 |
# File 'lib/zip-container/container.rb', line 138 def verify? verify.empty? ? true : false end |