class ZipContainer::ManagedFile
A ManagedFile
is used to reserve a filename in a Container
namespace.
Public Class Methods
Source
# File lib/zip-container/entries/file.rb 62 def initialize(name, options = {}) 63 options = { 64 required: false, 65 hidden: false, 66 validation_proc: nil 67 }.merge(options) 68 69 super(name, options[:required], options[:hidden]) 70 71 @validation_proc = 72 options[:validation_proc].is_a?(Proc) ? options[:validation_proc] : nil 73 end
Create a new ManagedFile
with the supplied name. Options that can be passed in are:
-
:required
whether it is required to exist or not (default false). -
:hidden
whether it is hidden for normal operations. -
:validation_proc
should be a Proc that takes a single parameter, to which will be supplied the contents of the file, and returnstrue
orfalse
depending on whether the contents of the file were validated or not (default nil).
For more complex content validation subclasses may override the validate method.
The following example creates a ManagedFile
that is not required to be present in the container, but if it is, its contents must be the single word “Boo!”.
valid = Proc.new { |contents| contents == "Boo!" } ManagedFile.new("Surprize.txt", required: false, validation_proc: valid)
ZipContainer::ManagedEntry::new
Public Instance Methods
Source
# File lib/zip-container/entries/file.rb 83 def verify 84 messages = super 85 86 valid = exists? ? validate : true 87 unless valid 88 messages << 89 "The contents of file '#{full_name}' do not pass validation." 90 end 91 92 messages 93 end
Verify this ManagedFile
for correctness. The contents are validated if required.
If it does not pass verification a list of reasons why it fails is returned. The empty list is returned if verification passes.
ZipContainer::ManagedEntry#verify
Protected Instance Methods
Source
# File lib/zip-container/entries/file.rb 105 def validate 106 @validation_proc.nil? ? true : @validation_proc.call(contents) 107 end
Validate the contents of this ManagedFile
. By default this methods uses the validation Proc supplied on object initialization if there is one. If not it simply returns true (no validation was required).
For complex validations of content subclasses can override this method.