Mechanize::DirectorySaver

Unlike Mechanize::FileSaver, the directory saver places all downloaded files in a single pre-specified directory.

You must register the directory to save to before using the directory saver:

  agent.pluggable_parser['image'] = \
    Mechanize::DirectorySaver.save_to 'images'

Public Class Methods

directory() click to toggle source

The directory downloaded files will be saved to.

    # File lib/mechanize/directory_saver.rb, line 29
29:   def self.directory
30:     @directory
31:   end
new(uri = nil, response = nil, body_io = nil, code = nil) click to toggle source

Saves the body_io into the directory specified for this DirectorySaver by save_to. The filename is chosen by Mechanize::Parser#extract_filename.

    # File lib/mechanize/directory_saver.rb, line 37
37:   def initialize uri = nil, response = nil, body_io = nil, code = nil
38:     directory = self.class.directory
39: 
40:     raise Mechanize::Error,
41:       'no save directory specified - '        'use Mechanize::DirectorySaver.save_to '        'and register the resulting class' unless directory
42: 
43:     super
44: 
45:     path = File.join directory, @filename
46: 
47:     save path
48:   end
save_to(directory) click to toggle source

Creates a DirectorySaver subclass that will save responses to the given directory.

    # File lib/mechanize/directory_saver.rb, line 18
18:   def self.save_to directory
19:     directory = File.expand_path directory
20: 
21:     Class.new self do |klass|
22:       klass.instance_variable_set :@directory, directory
23:     end
24:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.