[前][次][番号順一覧][スレッド一覧]

ruby-changes:44225

From: hsbt <ko1@a...>
Date: Fri, 30 Sep 2016 19:06:29 +0900 (JST)
Subject: [ruby-changes:44225] hsbt:r56298 (trunk): * lib/uri/http.rb: Documentation and code style imrovements.

hsbt	2016-09-30 19:06:24 +0900 (Fri, 30 Sep 2016)

  New Revision: 56298

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56298

  Log:
    * lib/uri/http.rb: Documentation and code style imrovements.
    * test/uri/test_http.rb: Added test for coverage.
      [fix GH-1427][ruby-core:77255][Misc #12756]

  Modified files:
    trunk/ChangeLog
    trunk/lib/uri/http.rb
    trunk/test/uri/test_http.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56297)
+++ ChangeLog	(revision 56298)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Sep 30 19:06:21 2016  Anton Davydov  <mail@d...>
+
+	* lib/uri/http.rb: Documentation and code style imrovements.
+	* test/uri/test_http.rb: Added test for coverage.
+	  [fix GH-1427][ruby-core:77255][Misc #12756]
+
 Fri Sep 30 18:43:20 2016  Jason Yeo  <jason@j...>
 
 	* doc/syntax/control_expressions.rdoc: Add missing 'as'
Index: lib/uri/http.rb
===================================================================
--- lib/uri/http.rb	(revision 56297)
+++ lib/uri/http.rb	(revision 56298)
@@ -25,12 +25,12 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/http.rb#L25
     DEFAULT_PORT = 80
 
     # An Array of the available components for URI::HTTP
-    COMPONENT = [
-      :scheme,
-      :userinfo, :host, :port,
-      :path,
-      :query,
-      :fragment
+    COMPONENT = %i[
+      scheme
+      userinfo host port
+      path
+      query
+      fragment
     ].freeze
 
     #
@@ -49,8 +49,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/http.rb#L49
     #
     # Example:
     #
-    #     newuri = URI::HTTP.build({:host => 'www.example.com',
-    #       :path => '/foo/bar'})
+    #     newuri = URI::HTTP.build(host: 'www.example.com', path: '/foo/bar')
     #
     #     newuri = URI::HTTP.build([nil, "www.example.com", nil, "/path",
     #       "query", 'fragment'])
@@ -59,8 +58,8 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/http.rb#L58
     # invalid HTTP URIs as per RFC 1738.
     #
     def self.build(args)
-      tmp = Util::make_components_hash(self, args)
-      return super(tmp)
+      tmp = Util.make_components_hash(self, args)
+      super(tmp)
     end
 
 =begin
@@ -95,15 +94,19 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/http.rb#L94
     # If the URI contains a query, the full path is URI#path + '?' + URI#query.
     # Otherwise, the path is simply URI#path.
     #
+    # Example:
+    #
+    #     newuri = URI::HTTP.build(path: '/foo/bar', query: 'test=true')
+    #     newuri.request_uri # => "/foo/bar?test=true"
+    #
     def request_uri
-      return nil unless @path
-      if @path.start_with?(?/.freeze)
-        @query ? "#@path?#@query" : @path.dup
-      else
-        @query ? "/#@path?#@query" : "/#@path"
-      end
+      return unless @path
+
+      url = @query ? "#@path?#@query" : @path.dup
+      url.start_with?(?/.freeze) ? url : ?/ + url
     end
   end
 
   @@schemes['HTTP'] = HTTP
+
 end
Index: test/uri/test_http.rb
===================================================================
--- test/uri/test_http.rb	(revision 56297)
+++ test/uri/test_http.rb	(revision 56298)
@@ -16,6 +16,11 @@ class TestHTTP < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/uri/test_http.rb#L16
     uri.class.component.collect {|c| uri.send(c)}
   end
 
+  def test_build
+    u = URI::HTTP.build(host: 'www.example.com', path: '/foo/bar')
+    assert_kind_of(URI::HTTP, u)
+  end
+
   def test_parse
     u = URI.parse('http://a')
     assert_kind_of(URI::HTTP, u)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]