2018-03-15 12:51:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-02 13:52:33 -04:00
|
|
|
require_relative 'generic'
|
2018-03-15 12:51:31 -04:00
|
|
|
|
|
|
|
module URI
|
|
|
|
|
|
|
|
#
|
2018-04-17 15:46:25 -04:00
|
|
|
# The "file" URI is defined by RFC8089.
|
2018-03-15 12:51:31 -04:00
|
|
|
#
|
|
|
|
class File < Generic
|
2018-04-17 15:46:25 -04:00
|
|
|
# A Default port of nil for URI::File.
|
2018-03-15 12:51:31 -04:00
|
|
|
DEFAULT_PORT = nil
|
|
|
|
|
|
|
|
#
|
2018-04-17 15:46:25 -04:00
|
|
|
# An Array of the available components for URI::File.
|
2018-03-15 12:51:31 -04:00
|
|
|
#
|
|
|
|
COMPONENT = [
|
|
|
|
:scheme,
|
|
|
|
:host,
|
|
|
|
:path
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
#
|
|
|
|
# == Description
|
|
|
|
#
|
|
|
|
# Creates a new URI::File object from components, with syntax checking.
|
|
|
|
#
|
|
|
|
# The components accepted are +host+ and +path+.
|
|
|
|
#
|
|
|
|
# The components should be provided either as an Array, or as a Hash
|
|
|
|
# with keys formed by preceding the component names with a colon.
|
|
|
|
#
|
2018-04-17 15:46:25 -04:00
|
|
|
# If an Array is used, the components must be passed in the
|
|
|
|
# order <code>[host, path]</code>.
|
2018-03-15 12:51:31 -04:00
|
|
|
#
|
2018-04-17 15:46:25 -04:00
|
|
|
# Examples:
|
2018-03-15 12:51:31 -04:00
|
|
|
#
|
|
|
|
# require 'uri'
|
|
|
|
#
|
2018-04-17 15:46:25 -04:00
|
|
|
# uri1 = URI::File.build(['host.example.com', '/path/file.zip'])
|
|
|
|
# uri1.to_s # => "file://host.example.com/path/file.zip"
|
2018-03-15 12:51:31 -04:00
|
|
|
#
|
|
|
|
# uri2 = URI::File.build({:host => 'host.example.com',
|
2018-04-17 15:47:57 -04:00
|
|
|
# :path => '/ruby/src'})
|
2018-04-17 15:46:25 -04:00
|
|
|
# uri2.to_s # => "file://host.example.com/ruby/src"
|
2018-03-15 12:51:31 -04:00
|
|
|
#
|
|
|
|
def self.build(args)
|
|
|
|
tmp = Util::make_components_hash(self, args)
|
|
|
|
super(tmp)
|
|
|
|
end
|
|
|
|
|
2018-04-21 16:04:05 -04:00
|
|
|
# Protected setter for the host component +v+.
|
2018-03-15 12:51:31 -04:00
|
|
|
#
|
2018-04-21 16:04:05 -04:00
|
|
|
# See also URI::Generic.host=.
|
2018-03-15 12:51:31 -04:00
|
|
|
#
|
|
|
|
def set_host(v)
|
|
|
|
v = "" if v.nil? || v == "localhost"
|
|
|
|
@host = v
|
|
|
|
end
|
|
|
|
|
|
|
|
# do nothing
|
|
|
|
def set_port(v)
|
|
|
|
end
|
|
|
|
|
|
|
|
# raise InvalidURIError
|
|
|
|
def check_userinfo(user)
|
|
|
|
raise URI::InvalidURIError, "can not set userinfo for file URI"
|
|
|
|
end
|
|
|
|
|
|
|
|
# raise InvalidURIError
|
|
|
|
def check_user(user)
|
|
|
|
raise URI::InvalidURIError, "can not set user for file URI"
|
|
|
|
end
|
|
|
|
|
|
|
|
# raise InvalidURIError
|
|
|
|
def check_password(user)
|
|
|
|
raise URI::InvalidURIError, "can not set password for file URI"
|
|
|
|
end
|
|
|
|
|
|
|
|
# do nothing
|
|
|
|
def set_userinfo(v)
|
|
|
|
end
|
|
|
|
|
|
|
|
# do nothing
|
|
|
|
def set_user(v)
|
|
|
|
end
|
|
|
|
|
|
|
|
# do nothing
|
|
|
|
def set_password(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@@schemes['FILE'] = File
|
|
|
|
end
|