lib/rufus/verbs/verbose.rb in rufus-verbs-0.10 vs lib/rufus/verbs/verbose.rb in rufus-verbs-1.0.0
- old
+ new
@@ -1,114 +1,105 @@
-#
#--
-# Copyright (c) 2008, John Mettraux, jmettraux@gmail.com
+# Copyright (c) 2008-2010, John Mettraux, jmettraux@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
-#
+#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
-#
+#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
-# (MIT license)
+# Made in Japan.
#++
-#
-#
-# John Mettraux
-#
-# Made in Japan
-#
-# 2008/03/31
-#
module Rufus
module Verbs
+ #
+ # Methods for the verbose mode
+ #
+ module VerboseMixin
+
+ protected
+
#
- # Methods for the verbose mode
+ # logs a unique message to the verbose channel (if any).
#
- module VerboseMixin
+ def vlog (opts, msg)
- protected
+ channel = get_channel(opts) or return
- #
- # logs a unique message to the verbose channel (if any).
- #
- def vlog (opts, msg)
+ channel << msg
+ end
- channel = get_channel(opts) or return
+ #
+ # logs the outgoing request
+ #
+ def vlog_request (opts, req)
- channel << msg
- end
+ channel = get_channel(opts) or return
- #
- # logs the outgoing request
- #
- def vlog_request (opts, req)
+ channel << "> #{req.method} #{req.path}\n"
- channel = get_channel(opts) or return
+ req.each do |k, v|
+ channel << "> #{k}: #{v}\n"
+ end
- channel << "> #{req.method} #{req.path}\n"
+ channel << ">\n"
+ end
- req.each do |k, v|
- channel << "> #{k}: #{v}\n"
- end
+ def vlog_http (opts, http)
- channel << ">\n"
- end
+ channel = get_channel(opts) or return
- def vlog_http (opts, http)
+ channel << "* #{http.address}:#{http.port}\n"
+ channel << "*\n"
+ end
- channel = get_channel(opts) or return
+ #
+ # logs the incoming response
+ #
+ def vlog_response (opts, res)
- channel << "* #{http.address}:#{http.port}\n"
- channel << "*\n"
- end
+ channel = get_channel(opts) or return
- #
- # logs the incoming response
- #
- def vlog_response (opts, res)
+ channel << "< #{res.code} #{res.message}\n"
+ channel << "<\n"
- channel = get_channel(opts) or return
+ res.each do |k, v|
+ channel << "< #{k}: #{v}\n"
+ end
- channel << "< #{res.code} #{res.message}\n"
- channel << "<\n"
+ channel << "<\n"
+ end
- res.each do |k, v|
- channel << "< #{k}: #{v}\n"
- end
+ private
- channel << "<\n"
- end
+ def get_channel (opts)
- private
+ v = o(opts, [ :verbose, :v ])
- def get_channel (opts)
+ return nil if (not v) or (v.to_s == 'false')
- v = o(opts, [ :verbose, :v ])
+ v = $stdout if v.to_s == 'true'
- return nil if (not v) or (v.to_s == 'false')
+ return nil unless v.is_a?(IO)
- v = $stdout if v.to_s == 'true'
-
- return nil unless v.is_a?(IO)
-
- v
- end
+ v
end
+ end
end
end