Class: ZipContainer::ManagedEntry
- Inherits:
-
Object
- Object
- ZipContainer::ManagedEntry
- Includes:
- Util
- Defined in:
- lib/zip-container/entries/entry.rb
Overview
ManagedEntry is the superclass of ManagedDirectory and ManagedFile. It should not be used directly but may be subclassed if necessary.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the ManagedEntry.
-
#parent ⇒ Object
writeonly
Allows the object in which this entry has been registered to tell it who it is.
Instance Method Summary collapse
-
#exists? ⇒ Boolean
:call-seq: exists? -> true or false.
-
#full_name ⇒ Object
:call-seq: full_name -> string.
-
#hidden? ⇒ Boolean
:call-seq: hidden? -> true or false.
-
#initialize(name, required, hidden) ⇒ ManagedEntry
constructor
:call-seq: new(name, required) -> ManagedEntry.
-
#required? ⇒ Boolean
:call-seq: required? -> true or false.
-
#verify ⇒ Object
:call-seq: verify -> Array.
-
#verify! ⇒ Object
:call-seq: verify!.
-
#verify? ⇒ Boolean
:call-seq: verify? -> true or false.
Methods included from Util
Constructor Details
#initialize(name, required, hidden) ⇒ ManagedEntry
:call-seq:
new(name, required) -> ManagedEntry
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.
56 57 58 59 60 61 |
# File 'lib/zip-container/entries/entry.rb', line 56 def initialize(name, required, hidden) @parent = nil @name = name @required = required @hidden = hidden end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the ManagedEntry. For the full path name of this entry use full_name.
44 45 46 |
# File 'lib/zip-container/entries/entry.rb', line 44 def name @name end |
#parent=(value) ⇒ Object (writeonly)
Allows the object in which this entry has been registered to tell it who it is.
48 49 50 |
# File 'lib/zip-container/entries/entry.rb', line 48 def parent=(value) @parent = value end |
Instance Method Details
#exists? ⇒ Boolean
:call-seq:
exists? -> true or false
Does this ManagedEntry exist in the Container?
101 102 103 104 105 106 107 108 |
# 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 ⇒ Object
:call-seq:
full_name -> string
The fully qualified name of this ManagedEntry.
67 68 69 70 71 72 73 |
# 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? ⇒ Boolean
:call-seq:
hidden? -> true or false
Is this ManagedEntry hidden for normal operations?
88 89 90 91 92 93 94 95 |
# 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? ⇒ Boolean
:call-seq:
required? -> true or false
Is this ManagedEntry required to be present according to the specification of its Container?
80 81 82 |
# File 'lib/zip-container/entries/entry.rb', line 80 def required? @required end |
#verify ⇒ Object
:call-seq:
verify -> Array
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.
118 119 120 121 122 123 124 |
# 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! ⇒ Object
:call-seq:
verify!
Verify this ManagedEntry raising a MalformedContainerError if it fails.
141 142 143 144 |
# File 'lib/zip-container/entries/entry.rb', line 141 def verify! = verify raise MalformedContainerError, unless .empty? end |
#verify? ⇒ Boolean
:call-seq:
verify? -> true or false
Verify this ManagedEntry by checking that it exists if it is required according to its Container specification and validating its contents if necessary.
132 133 134 |
# File 'lib/zip-container/entries/entry.rb', line 132 def verify? verify.empty? end |