ManagedEntry is the superclass of ManagedDirectory and ManagedFile. It should not be used directly but may be subclassed if necessary.
The name of the ManagedEntry. For the full path name of this entry use full_name.
Create a new ManagedEntry with the supplied name. The entry should also be marked as required or not.
# File lib/zip-container/entries/entry.rb, line 49 def initialize(name, required) @parent = nil @name = name @required = required end
Does this ManagedEntry exist in the Container?
# File lib/zip-container/entries/entry.rb, line 76 def exists? container.entries.each do |entry| test = (entry.ftype == :directory) ? "#{full_name}/" : full_name return true if entry.name == test end false end
The fully qualified name of this ManagedEntry.
# File lib/zip-container/entries/entry.rb, line 59 def full_name @parent.is_a?(Container) ? @name : "#{@parent.name}/#{@name}" end
Is this ManagedEntry required to be present according to the specification of its Container?
# File lib/zip-container/entries/entry.rb, line 68 def required? @required end
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 99 def verify begin verify! rescue return false end true end
Return the Container that this ManagedEntry resides in.
# File lib/zip-container/entries/entry.rb, line 130 def container @parent.is_a?(Container) ? @parent : @parent.container end
Verify this ManagedEntry raising a MalformedContainerError if it fails.
Subclasses should override this method if they require more complex verification to be done.
# File lib/zip-container/entries/entry.rb, line 119 def verify! unless !@required || exists? raise MalformedContainerError.new("Entry '#{full_name}' is required " "but missing.") end end