1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
##
# This is a pluggable parser that automatically saves every file it
# encounters. Unlike Mechanize::DirectorySaver, the file saver saves the
# responses as a tree, reflecting the host and file path.
#
# == Example
#
# This example saves all .pdf files
#
# require 'mechanize'
#
# agent = Mechanize.new
# agent.pluggable_parser.pdf = Mechanize::FileSaver
# agent.get 'http://example.com/foo.pdf'
#
# Dir['example.com/*'] # => foo.pdf
class Mechanize::FileSaver < Mechanize::Download
attr_reader :filename
def initialize uri = nil, response = nil, body_io = nil, code = nil
@full_path = true
super
save @filename
end
##
# The save_as alias is provided for backwards compatibility with mechanize
# 2.0. It will be removed in mechanize 3.
#--
# TODO remove in mechanize 3
alias save_as save
end
|