module Anyfetch

Constants

VERSION

Public Instance Methods

open(uri, options = {}) click to toggle source
# File lib/anyfetch.rb, line 11
def open(uri, options = {})
  uri = to_uri(uri)
  handler(uri, options).open
end

Private Instance Methods

handler(uri, options = {}) click to toggle source
# File lib/anyfetch.rb, line 22
def handler(uri, options = {})
  scheme = uri.scheme || "file"

  klass =
    case scheme
    when "file"    then File
    when "ftp"     then FTP
    when "sftp"    then SFTP
    when /^https?/ then HTTP
    else
      raise "No handler for '#{scheme}' protocol."
    end

  klass.new(uri, options)
end
to_uri(uri) click to toggle source
# File lib/anyfetch.rb, line 18
def to_uri(uri)
  URI.parse(uri.to_s)
end