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'
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 ReservedNames
#reserved_entry?, #reserved_names
Constructor Details
#initialize(location) ⇒ Container
Returns a new instance of Container.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/zip-container/container.rb', line 57 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.
51 52 53 |
# File 'lib/zip-container/container.rb', line 51 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.
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/zip-container/container.rb', line 77 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.
98 99 100 |
# File 'lib/zip-container/container.rb', line 98 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 an error if there is something fundamental wrong with the container itself (e.g. it cannot be found).
120 121 122 |
# File 'lib/zip-container/container.rb', line 120 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.
110 111 112 |
# File 'lib/zip-container/container.rb', line 110 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.
129 130 131 |
# File 'lib/zip-container/container.rb', line 129 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.
153 154 155 156 157 |
# File 'lib/zip-container/container.rb', line 153 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.
141 142 143 |
# File 'lib/zip-container/container.rb', line 141 def verify? verify.empty? end |