lib/zip-container/entries/entry.rb in zip-container-1.1.0 vs lib/zip-container/entries/entry.rb in zip-container-2.0.0
- old
+ new
@@ -34,32 +34,35 @@
module ZipContainer
# ManagedEntry is the superclass of ManagedDirectory and ManagedFile. It
# should not be used directly but may be subclassed if necessary.
class ManagedEntry
+ include Util
# The name of the ManagedEntry. For the full path name of this entry use
# full_name.
attr_reader :name
# :call-seq:
# new(name, required) -> ManagedEntry
#
# Create a new ManagedEntry with the supplied name. The entry should also
- # be marked as required or not.
- def initialize(name, required)
+ # be marked as required or not and whether it is hidden for normal
+ # operations.
+ def initialize(name, required, hidden)
@parent = nil
@name = name
@required = required
+ @hidden = hidden
end
# :call-seq:
# full_name -> string
#
# The fully qualified name of this ManagedEntry.
def full_name
- @parent.is_a?(Container) ? @name : "#{@parent.name}/#{@name}"
+ @parent.is_a?(ZipContainer::File) ? @name : "#{@parent.full_name}/#{@name}"
end
# :call-seq:
# required? -> true or false
#
@@ -68,10 +71,19 @@
def required?
@required
end
# :call-seq:
+ # hidden? -> true or false
+ #
+ # Is this ManagedEntry hidden for normal operations?
+ def hidden?
+ # An entry is hidden if its parent is hidden.
+ @parent.is_a?(ZipContainer::File) ? @hidden : @hidden || @parent.hidden?
+ end
+
+ # :call-seq:
# exists? -> true or false
#
# Does this ManagedEntry exist in the Container?
def exists?
container.entries.each do |entry|
@@ -126,10 +138,10 @@
# :call-seq:
# container -> Container
#
# Return the Container that this ManagedEntry resides in.
def container
- @parent.is_a?(Container) ? @parent : @parent.container
+ @parent.is_a?(ZipContainer::File) ? @parent : @parent.container
end
end
end