Class: Mechanize::DirectorySaver

### Home Classes Methods

### In Files

- lib/mechanize/directory_saver.rb

### Parent

Mechanize::Download

### Methods

- ::decode_filename?
- ::directory
- ::new
- ::save_to

### Files

- EXAMPLES.rdoc
- GUIDE.rdoc
- LICENSE.rdoc
- Manifest.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Mechanize
- Mechanize::ChunkedTerminationError
- Mechanize::ContentTypeError
- Mechanize::Cookie
- Mechanize::CookieCMethods
- Mechanize::CookieDeprecated
- Mechanize::CookieIMethods
- Mechanize::CookieJar
- Mechanize::CookieJarIMethods
- Mechanize::DirectorySaver
- Mechanize::Download
- Mechanize::ElementMatcher
- Mechanize::Error
- Mechanize::File
- Mechanize::FileConnection
- Mechanize::FileRequest
- Mechanize::FileResponse
- Mechanize::FileSaver
- Mechanize::Form
- Mechanize::Form::Button
- Mechanize::Form::CheckBox
- Mechanize::Form::Field
- Mechanize::Form::FileUpload
- Mechanize::Form::Hidden
- Mechanize::Form::ImageButton
- Mechanize::Form::Keygen
- Mechanize::Form::MultiSelectList
- Mechanize::Form::Option
- Mechanize::Form::RadioButton
- Mechanize::Form::Reset
- Mechanize::Form::SelectList
- Mechanize::Form::Submit
- Mechanize::Form::Text
- Mechanize::Form::Textarea
- Mechanize::HTTP
- Mechanize::HTTP::Agent
- Mechanize::HTTP::AuthChallenge
- Mechanize::HTTP::AuthRealm
- Mechanize::HTTP::AuthStore
- Mechanize::HTTP::ContentDispositionParser
- Mechanize::HTTP::WWWAuthenticateParser
- Mechanize::Headers
- Mechanize::History
- Mechanize::Image
- Mechanize::Page
- Mechanize::Page::Base
- Mechanize::Page::Frame
- Mechanize::Page::Image
- Mechanize::Page::Label
- Mechanize::Page::Link
- Mechanize::Page::MetaRefresh
- Mechanize::Parser
- Mechanize::PluggableParser
- Mechanize::Prependable
- Mechanize::RedirectLimitReachedError
- Mechanize::RedirectNotGetOrHeadError
- Mechanize::ResponseCodeError
- Mechanize::ResponseReadError
- Mechanize::RobotsDisallowedError
- Mechanize::TestCase
- Mechanize::UnauthorizedError
- Mechanize::UnsupportedSchemeError
- Mechanize::Util
- Mechanize::XmlFile
- HTTP
- HTTP::CookieJar

No matching classes.

# 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

decode_filename?() click to toggle source

True if downloaded files should have their names decoded before saving.

    # File lib/mechanize/directory_saver.rb, line 40
    def self.decode_filename?
      @options[:decode_filename]
    end

directory() click to toggle source

The directory downloaded files will be saved to.

    # File lib/mechanize/directory_saver.rb, line 33
    def self.directory
      @directory
    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 48
    def initialize uri = nil, response = nil, body_io = nil, code = nil
      directory = self.class.directory

      raise Mechanize::Error,
        'no save directory specified - '        'use Mechanize::DirectorySaver.save_to '        'and register the resulting class' unless directory

      super

      @filename = CGI.unescape(@filename) if self.class.decode_filename?
      path = File.join directory, @filename

      save path
    end

save_to(directory, options = {}) click to toggle source

Creates a DirectorySaver subclass that will save responses to the given `directory`. If `options` includes a `decode_filename` value set to `true` then the downloaded filename will be ran through `CGI.unescape` before being saved.

    # File lib/mechanize/directory_saver.rb, line 21
    def self.save_to directory, options = {}
      directory = File.expand_path directory

      Class.new self do |klass|
        klass.instance_variable_set :@directory, directory
        klass.instance_variable_set :@options, options
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.