Sha256: f4b751586d41758fc76001db860e1fb0f542bfe313d74615b16de8b42282c63d

Contents?: true

Size: 845 Bytes

Versions: 24

Compression:

Stored size: 845 Bytes

Contents

##
# 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

Version data entries

24 entries across 24 versions & 3 rubygems

Version Path
mechanize-2.7.7 lib/mechanize/file_saver.rb
husc-0.2.1 vendor/bundle/gems/mechanize-2.7.6/lib/mechanize/file_saver.rb
husc-0.2.0 vendor/bundle/gems/mechanize-2.7.6/lib/mechanize/file_saver.rb
husc-0.1.1 vendor/bundle/gems/mechanize-2.7.6/lib/mechanize/file_saver.rb
husc-0.1.0 vendor/bundle/gems/mechanize-2.7.6/lib/mechanize/file_saver.rb
mechanize-2.7.6 lib/mechanize/file_saver.rb
mechanize-2.7.5 lib/mechanize/file_saver.rb
mechanize-2.7.4 lib/mechanize/file_saver.rb
mechanize-2.7.3 lib/mechanize/file_saver.rb
mechanize-2.7.2 lib/mechanize/file_saver.rb
mechanize-2.7.1 lib/mechanize/file_saver.rb
mechanize-2.7.0 lib/mechanize/file_saver.rb
mechanize-2.6.0 lib/mechanize/file_saver.rb
mechanize-2.5.1 lib/mechanize/file_saver.rb
mechanize-2.5 lib/mechanize/file_saver.rb
mechanize-2.4 lib/mechanize/file_saver.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/file_saver.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/file_saver.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/file_saver.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/file_saver.rb