class ZipContainer::ManagedEntry
ManagedEntry
is the superclass of ManagedDirectory
and ManagedFile
. It should not be used directly but may be subclassed if necessary.
Attributes
The name of the ManagedEntry
. For the full path name of this entry use full_name.
Public Class Methods
Source
# File lib/zip-container/entries/entry.rb 56 def initialize(name, required, hidden) 57 @parent = nil 58 @name = name 59 @required = required 60 @hidden = hidden 61 end
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.
Public Instance Methods
Source
# File lib/zip-container/entries/entry.rb 101 def exists? 102 container.entries.each do |entry| 103 test = entry.ftype == :directory ? "#{full_name}/" : full_name 104 return true if entry.name == test 105 end 106 107 false 108 end
Does this ManagedEntry
exist in the Container
?
Source
# File lib/zip-container/entries/entry.rb 67 def full_name 68 if @parent.is_a?(ZipContainer::Container) 69 @name 70 else 71 "#{@parent.full_name}/#{@name}" 72 end 73 end
The fully qualified name of this ManagedEntry
.
Source
# File lib/zip-container/entries/entry.rb 80 def required? 81 @required 82 end
Is this ManagedEntry
required to be present according to the specification of its Container
?
Source
# File lib/zip-container/entries/entry.rb 118 def verify 119 if @required && !exists? 120 ["Entry '#{full_name}' is required but missing."] 121 else 122 [] 123 end 124 end
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.
Source
# File lib/zip-container/entries/entry.rb 141 def verify! 142 messages = verify 143 raise MalformedContainerError, messages unless messages.empty? 144 end
Verify this ManagedEntry
raising a MalformedContainerError
if it fails.
Source
# File lib/zip-container/entries/entry.rb 132 def verify? 133 verify.empty? 134 end
Verify this ManagedEntry
by checking that it exists if it is required according to its Container
specification and validating its contents if necessary.
Protected Instance Methods
Source
# File lib/zip-container/entries/entry.rb 152 def container 153 @parent.is_a?(ZipContainer::Container) ? @parent : @parent.container 154 end
Return the Container
that this ManagedEntry
resides in.