class ZipContainer::ManagedEntry

ManagedEntry is the superclass of ManagedDirectory and ManagedFile. It should not be used directly but may be subclassed if necessary.

Attributes

name[R]

The name of the ManagedEntry. For the full path name of this entry use full_name.

Public Class Methods

new(name, required) → ManagedEntry click to toggle source

Create a new ManagedEntry with the supplied name. The entry should also be marked as required or not and whether it is hidden for normal operations.

# File lib/zip-container/entries/entry.rb, line 56
def initialize(name, required, hidden)
  @parent = nil
  @name = name
  @required = required
  @hidden = hidden
end

Public Instance Methods

exists? → true or false click to toggle source

Does this ManagedEntry exist in the Container?

# File lib/zip-container/entries/entry.rb, line 101
def exists?
  container.entries.each do |entry|
    test = entry.ftype == :directory ? "#{full_name}/" : full_name
    return true if entry.name == test
  end

  false
end
full_name → string click to toggle source

The fully qualified name of this ManagedEntry.

# File lib/zip-container/entries/entry.rb, line 67
def full_name
  if @parent.is_a?(ZipContainer::Container)
    @name
  else
    "#{@parent.full_name}/#{@name}"
  end
end
hidden? → true or false click to toggle source

Is this ManagedEntry hidden for normal operations?

# File lib/zip-container/entries/entry.rb, line 88
def hidden?
  # An entry is hidden if its parent is hidden.
  if @parent.is_a?(ZipContainer::Container)
    @hidden
  else
    @hidden || @parent.hidden?
  end
end
required? → true or false click to toggle source

Is this ManagedEntry required to be present according to the specification of its Container?

# File lib/zip-container/entries/entry.rb, line 80
def required?
  @required
end
verify → Array click to toggle source

Verify this ManagedEntry returning a list of reasons why it fails if it does so. The empty list is returned if verification passes.

Subclasses should override this method if they require more complex verification to be done.

# File lib/zip-container/entries/entry.rb, line 118
def verify
  if @required && !exists?
    ["Entry '#{full_name}' is required but missing."]
  else
    []
  end
end
verify! click to toggle source

Verify this ManagedEntry raising a MalformedContainerError if it fails.

# File lib/zip-container/entries/entry.rb, line 141
def verify!
  messages = verify
  raise MalformedContainerError, messages unless messages.empty?
end
verify? → true or false click to toggle source

Verify this ManagedEntry by checking that it exists if it is required according to its Container specification and validating its contents if necessary.

# File lib/zip-container/entries/entry.rb, line 132
def verify?
  verify.empty?
end

Protected Instance Methods

container → Container click to toggle source

Return the Container that this ManagedEntry resides in.

# File lib/zip-container/entries/entry.rb, line 152
def container
  @parent.is_a?(ZipContainer::Container) ? @parent : @parent.container
end