Parent

Class Index [+]

Quicksearch

Mechanize::FileResponse

 

Fake response for dealing with file:/// requests

Public Class Methods

new(file_path) click to toggle source
   # File lib/mechanize/file_response.rb, line 5
5:     def initialize(file_path)
6:       @file_path = file_path
7:     end

Public Instance Methods

[](key) click to toggle source
    # File lib/mechanize/file_response.rb, line 32
32:     def [](key)
33:       return nil unless key.downcase == 'content-type'
34:       return 'text/html' if directory?
35:       return 'text/html' if ['.html', '.xhtml'].any? { |extn|
36:         @file_path =~ /#{extn}$/
37:       }
38:       nil
39:     end
code() click to toggle source
    # File lib/mechanize/file_response.rb, line 21
21:     def code
22:       ::File.exists?(@file_path) ? 200 : 400
23:     end
content_length() click to toggle source
    # File lib/mechanize/file_response.rb, line 25
25:     def content_length
26:       return dir_body.length if directory?
27:       ::File.exists?(@file_path) ? ::File.stat(@file_path).size : 0
28:     end
each() click to toggle source
    # File lib/mechanize/file_response.rb, line 41
41:     def each
42:     end
each_header() click to toggle source
    # File lib/mechanize/file_response.rb, line 30
30:     def each_header; end
get_fields(key) click to toggle source
    # File lib/mechanize/file_response.rb, line 44
44:     def get_fields(key)
45:       []
46:     end
read_body() click to toggle source
    # File lib/mechanize/file_response.rb, line 9
 9:     def read_body
10:       if ::File.exists?(@file_path)
11:         if directory?
12:           yield dir_body
13:         else
14:           yield ::File.read(@file_path)
15:         end
16:       else
17:         yield ''
18:       end
19:     end

Private Instance Methods

dir_body() click to toggle source
    # File lib/mechanize/file_response.rb, line 49
49:     def dir_body
50:       '<html><body>' +
51:         Dir[::File.join(@file_path, '*')].map { |f|
52:         "<a href=\"file://#{f}\">#{::File.basename(f)}</a>"
53:       }.join("\n") + '</body></html>'
54:     end
directory?() click to toggle source
    # File lib/mechanize/file_response.rb, line 56
56:     def directory?
57:       ::File.directory?(@file_path)
58:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.