Module: URI::Component
- Defined in:
- lib/uri/component.rb,
lib/uri/component/path.rb,
lib/uri/component/query.rb,
lib/uri/component/version.rb,
lib/uri/component/userinfo.rb
Overview
Handle URI components as an object
Defined Under Namespace
Modules: PathMixin, QueryMixin, UserInfoMixin Classes: Path, Query, QueryParamsHash, UserInfo
Constant Summary collapse
- VERSION =
:nodoc:
"0.0.5"
Class Method Summary collapse
-
.mixin(klass) ⇒ Object
Description.
Class Method Details
.mixin(klass) ⇒ Object
Description
Add the following instance methods to the class klass
:
- userinfo_component
-
Returns the userinfo component of the URI as URI::Component::UserInfo object.
- path_component
-
Returns the path component of the URI as URI::Component::Path object.
- query_component
-
Returns the query component of the URI as URI::Component::Query object.
Example
require "uri"
require "uri/component"
URI::Component.mixin(URI::HTTP)
u = URI.parse("http://bob:[email protected]/path?foo=12&bar=ab");
i = u.userinfo_component #=> URI::Component::Userinfo.new("bob:pass")
p = u.path_component #=> URI::Component::Path.new("/path")
q = u.query_component #=> URI::Component::Query.new("foo=12&bar=ab")
i.password = nil
p i.to_s #=> "bob"
p.nodes << "file"
p p.to_s #=> "/path/file"
q.params["baz"] = ["x y z"]
p q.to_s #=> "foo=12&bar=ab&baz=x+y+z"
p u.to_s #=> "http://[email protected]/path/file?foo=12&bar=ab&baz=x+y+z"
49 50 51 52 53 |
# File 'lib/uri/component.rb', line 49 def self.mixin(klass) URI::Component::UserInfo.mixin(klass) if klass.component.include?(:userinfo) URI::Component::Path.mixin(klass) if klass.component.include?(:path) URI::Component::Query.mixin(klass) if klass.component.include?(:query) end |