/usr/lib/ruby/vendor_ruby/mechanize/directory_saver.rb is in ruby-mechanize 2.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 40 41 42 43 44 45 46 47 48 49 50 51 52 | ##
# 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'
class Mechanize::DirectorySaver < Mechanize::Download
@directory = nil
##
# Creates a DirectorySaver subclass that will save responses to the given
# +directory+.
def self.save_to directory
directory = File.expand_path directory
Class.new self do |klass|
klass.instance_variable_set :@directory, directory
end
end
##
# The directory downloaded files will be saved to.
def self.directory
@directory
end
##
# Saves the +body_io+ into the directory specified for this DirectorySaver
# by save_to. The filename is chosen by Mechanize::Parser#extract_filename.
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
path = File.join directory, @filename
save path
end
end
|