module ZipContainer::ReservedNames

This module provides support for reserved names.

Public Instance Methods

reserved_entry?(entry) → boolean click to toggle source

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

# File lib/zip-container/entries/reserved.rb, line 71
def reserved_entry?(entry)
  name = entry.kind_of?(::Zip::ZipEntry) ? entry.name : entry
  name.chop! if name.end_with? "/"
  reserved_names.map { |n| n.downcase }.include? name.downcase
end
reserved_names → Array click to toggle source

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
# File lib/zip-container/entries/reserved.rb, line 62
def reserved_names
  @reserved_names ||= []
end

Protected Instance Methods

register_reserved_name(name) click to toggle source

Add a reserved name to the list.

# File lib/zip-container/entries/reserved.rb, line 83
def register_reserved_name(name)
  @reserved_names ||= []
  @reserved_names << name unless @reserved_names.include? name
end