Class: Mechanize::FileResponse
- Inherits:
-
Object
- Object
- Mechanize::FileResponse
- Defined in:
- lib/mechanize/file_response.rb
Overview
Fake response for dealing with file:/// requests
Instance Method Summary collapse
- #[](key) ⇒ Object
- #code ⇒ Object
- #content_length ⇒ Object
- #each ⇒ Object
- #each_header ⇒ Object
- #get_fields(key) ⇒ Object
-
#initialize(file_path) ⇒ FileResponse
constructor
A new instance of FileResponse.
- #read_body ⇒ Object
Constructor Details
#initialize(file_path) ⇒ FileResponse
Returns a new instance of FileResponse.
5 6 7 |
# File 'lib/mechanize/file_response.rb', line 5 def initialize(file_path) @file_path = file_path end |
Instance Method Details
#[](key) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/mechanize/file_response.rb', line 32 def [](key) return nil unless key.downcase == 'content-type' return 'text/html' if directory? return 'text/html' if ['.html', '.xhtml'].any? { |extn| @file_path =~ /#{extn}$/ } nil end |
#code ⇒ Object
21 22 23 |
# File 'lib/mechanize/file_response.rb', line 21 def code ::File.exists?(@file_path) ? '200' : '400' end |
#content_length ⇒ Object
25 26 27 28 |
# File 'lib/mechanize/file_response.rb', line 25 def content_length return dir_body.length if directory? ::File.exists?(@file_path) ? ::File.stat(@file_path).size : 0 end |
#each ⇒ Object
41 42 |
# File 'lib/mechanize/file_response.rb', line 41 def each end |
#each_header ⇒ Object
30 |
# File 'lib/mechanize/file_response.rb', line 30 def each_header; end |
#get_fields(key) ⇒ Object
44 45 46 |
# File 'lib/mechanize/file_response.rb', line 44 def get_fields(key) [] end |
#read_body ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/mechanize/file_response.rb', line 9 def read_body if ::File.exists?(@file_path) if directory? yield dir_body else yield ::File.read(@file_path) end else yield '' end end |