lib/zip-container/entries/file.rb in zip-container-1.1.0 vs lib/zip-container/entries/file.rb in zip-container-2.0.0

- old
+ new

@@ -37,29 +37,40 @@ class ManagedFile < ManagedEntry # :call-seq: # new(name, required = false, validation_proc = nil) -> ManagedFile # - # Create a new ManagedFile with the supplied name and whether it is - # required to exist or not. + # Create a new ManagedFile with the supplied name. Options that can + # be passed in are: + # * <tt>:required</tt> whether it is required to exist or not (default + # false). + # * <tt>:hidden</tt> whether it is hidden for normal operations. + # * <tt>:validation_proc</tt> should be a Proc that takes a single + # parameter, to which will be supplied the contents of the file, and + # returns +true+ or +false+ depending on whether the contents of the + # file were validated or not (default nil). # - # If supplied <tt>validation_proc</tt> should be a Proc that takes a - # single parameter and returns +true+ or +false+ depending on whether the - # contents of the file were validated or not. - # # 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", false, valid) - def initialize(name, required = false, validation_proc = nil) - super(name, required) + # ManagedFile.new("Surprize.txt", :required => false, + # :validation_proc => valid) + def initialize(name, options = {}) + options = { + :required => false, + :hidden => false, + :validation_proc => nil + }.merge(options) - @validation_proc = validation_proc.is_a?(Proc) ? validation_proc : nil + super(name, options[:required], options[:hidden]) + + @validation_proc = + options[:validation_proc].is_a?(Proc) ? options[:validation_proc] : nil end # :call-seq: # verify! #