Module: ZipContainer::ReservedNames

Included in:
Container, ManagedDirectory
Defined in:
lib/zip-container/reserved_names.rb

Overview

This module provides support for reserved names.

Instance Method Summary collapse

Instance Method Details

#reserved_entry?(entry) ⇒ Boolean

:call-seq:

reserved_entry?(entry) -> boolean

Is the given entry in the reserved list of names? A String or a Zip::Entry object can be passed in here.

Returns:

  • (Boolean)


72
73
74
75
# File 'lib/zip-container/reserved_names.rb', line 72

def reserved_entry?(entry)
  name = Util.entry_name(entry)
  reserved_names.map(&:downcase).include? name.downcase
end

#reserved_namesObject

:call-seq:

reserved_names -> Array

Return a list of reserved file and directory names for this ZipContainer file.

Reserved files and directories must be accessed directly by methods within Container (or subclasses of Container). This is because they are fundamental to the format and might need to exhibit certain properties (such as no compression) that must be preserved. The “mimetype” file is an example of such a reserved entry.

To add a reserved name to a subclass of Container simply add it to the list in the constructor (you must call the super constructor first!):

class MyContainer < ZipContainer::Container
  def initialize(filename)
    super(filename)

    register_reserved_name("my_reserved_name")
  end
end


63
64
65
# File 'lib/zip-container/reserved_names.rb', line 63

def reserved_names
  @reserved_names ||= []
end