Class: ZipContainer::Container

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

Dir, File

Constant Summary collapse

MIMETYPE_FILE =

:stopdoc: The reserved mimetype file name for standard ZipContainers.

'mimetype'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#mimetypeObject (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.

Returns:

  • (Boolean)


110
111
112
# File 'lib/zip-container/container.rb', line 110

def self.verify?(filename)
  new(filename).verify?
end

Instance Method Details

#verifyObject

: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.

Returns:

  • (Boolean)


141
142
143
# File 'lib/zip-container/container.rb', line 141

def verify?
  verify.empty?
end