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, &block) ⇒ 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.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/zip-container/container.rb', line 52 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.
46 47 48 |
# File 'lib/zip-container/container.rb', line 46 def mimetype @mimetype end |
Class Method Details
.open(filename, &block) ⇒ Object
:call-seq:
open(filename) -> container
open(filename) {|container| ...}
Open an existing ZipContainer. It will be checked for conformance upon first access.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/zip-container/container.rb', line 72 def self.open(filename, &block) 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.
93 94 95 |
# File 'lib/zip-container/container.rb', line 93 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).
116 117 118 |
# File 'lib/zip-container/container.rb', line 116 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.
105 106 107 |
# File 'lib/zip-container/container.rb', line 105 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.
125 126 127 |
# File 'lib/zip-container/container.rb', line 125 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.
149 150 151 152 153 154 155 |
# File 'lib/zip-container/container.rb', line 149 def verify! unless @mimetype_error.nil? raise MalformedContainerError.new(@mimetype_error) end 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.
137 138 139 |
# File 'lib/zip-container/container.rb', line 137 def verify? verify.empty? ? true : false end |