Class: Mechanize::FileResponse

### Home Classes Methods

### In Files

- lib/mechanize/file_response.rb

### Parent

Object

### Methods

- ::new
- #[]
- #code
- #content_length
- #each
- #each_header
- #get_fields
- #http_version
- #message
- #read_body
- #uri

### Files

- EXAMPLES.rdoc
- GUIDE.rdoc
- LICENSE.rdoc
- Manifest.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Mechanize
- Mechanize::ChunkedTerminationError
- Mechanize::ContentTypeError
- Mechanize::Cookie
- Mechanize::CookieCMethods
- Mechanize::CookieDeprecated
- Mechanize::CookieIMethods
- Mechanize::CookieJar
- Mechanize::CookieJarIMethods
- Mechanize::DirectorySaver
- Mechanize::Download
- Mechanize::ElementMatcher
- Mechanize::Error
- Mechanize::File
- Mechanize::FileConnection
- Mechanize::FileRequest
- Mechanize::FileResponse
- Mechanize::FileSaver
- Mechanize::Form
- Mechanize::Form::Button
- Mechanize::Form::CheckBox
- Mechanize::Form::Field
- Mechanize::Form::FileUpload
- Mechanize::Form::Hidden
- Mechanize::Form::ImageButton
- Mechanize::Form::Keygen
- Mechanize::Form::MultiSelectList
- Mechanize::Form::Option
- Mechanize::Form::RadioButton
- Mechanize::Form::Reset
- Mechanize::Form::SelectList
- Mechanize::Form::Submit
- Mechanize::Form::Text
- Mechanize::Form::Textarea
- Mechanize::HTTP
- Mechanize::HTTP::Agent
- Mechanize::HTTP::AuthChallenge
- Mechanize::HTTP::AuthRealm
- Mechanize::HTTP::AuthStore
- Mechanize::HTTP::ContentDispositionParser
- Mechanize::HTTP::WWWAuthenticateParser
- Mechanize::Headers
- Mechanize::History
- Mechanize::Image
- Mechanize::Page
- Mechanize::Page::Base
- Mechanize::Page::Frame
- Mechanize::Page::Image
- Mechanize::Page::Label
- Mechanize::Page::Link
- Mechanize::Page::MetaRefresh
- Mechanize::Parser
- Mechanize::PluggableParser
- Mechanize::Prependable
- Mechanize::RedirectLimitReachedError
- Mechanize::RedirectNotGetOrHeadError
- Mechanize::ResponseCodeError
- Mechanize::ResponseReadError
- Mechanize::RobotsDisallowedError
- Mechanize::TestCase
- Mechanize::UnauthorizedError
- Mechanize::UnsupportedSchemeError
- Mechanize::Util
- Mechanize::XmlFile
- HTTP
- HTTP::CookieJar

No matching classes.

# 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 6
    def initialize(file_path)
      @file_path = file_path
      @uri       = nil
    end

### Public Instance Methods

[](key) click to toggle source

    # File lib/mechanize/file_response.rb, line 35
    def [](key)
      return nil if key.casecmp('Content-Type') != 0
      return 'text/html' if directory?
      return 'text/html' if ['.html', '.xhtml'].any? { |extn|
        @file_path.end_with?(extn)
      }
      nil
    end

code() click to toggle source

    # File lib/mechanize/file_response.rb, line 24
    def code
      File.exist?(@file_path) ? 200 : 404
    end

content_length() click to toggle source

    # File lib/mechanize/file_response.rb, line 28
    def content_length
      return dir_body.length if directory?
      File.exist?(@file_path) ? File.stat(@file_path).size : 0
    end

each() click to toggle source

    # File lib/mechanize/file_response.rb, line 44
    def each
    end

each_header() click to toggle source

    # File lib/mechanize/file_response.rb, line 33
    def each_header; end

get_fields(key) click to toggle source

    # File lib/mechanize/file_response.rb, line 47
    def get_fields(key)
      []
    end

http_version() click to toggle source

    # File lib/mechanize/file_response.rb, line 51
    def http_version
      '0'
    end

message() click to toggle source

    # File lib/mechanize/file_response.rb, line 55
    def message
      File.exist?(@file_path) ? 'OK' : 'Not Found'
    end

read_body() click to toggle source

    # File lib/mechanize/file_response.rb, line 11
    def read_body
      raise Mechanize::ResponseCodeError.new(self) unless
        File.exist? @file_path

      if directory?
        yield dir_body
      else
        open @file_path, 'rb' do |io|
          yield io.read
        end
      end
    end

uri() click to toggle source

    # File lib/mechanize/file_response.rb, line 59
    def uri
      @uri ||= URI "file://#{@file_path}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.