summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/date.rb2
-rw-r--r--lib/fileutils.rb2
-rw-r--r--lib/irb/context.rb2
-rw-r--r--lib/open3.rb2
-rw-r--r--lib/parsedate.rb7
-rw-r--r--lib/pstore.rb12
-rw-r--r--lib/rdoc/generators/html_generator.rb6
-rw-r--r--lib/rdoc/generators/ri_generator.rb2
-rw-r--r--lib/rdoc/parsers/parse_c.rb156
-rw-r--r--lib/rdoc/parsers/parse_rb.rb22
-rw-r--r--lib/rdoc/parsers/parse_simple.rb6
-rw-r--r--lib/rexml/document.rb8
-rw-r--r--lib/rexml/element.rb2
-rw-r--r--lib/rexml/instruction.rb4
-rw-r--r--lib/rexml/xmldecl.rb108
-rw-r--r--lib/set.rb5
-rw-r--r--lib/time.rb72
-rw-r--r--lib/timeout.rb52
-rw-r--r--lib/wsdl/soap/definitions.rb4
-rw-r--r--lib/xmlrpc/parser.rb2
20 files changed, 330 insertions, 146 deletions
diff --git a/lib/date.rb b/lib/date.rb
index 9771825411..1cd4e08049 100644
--- a/lib/date.rb
+++ b/lib/date.rb
@@ -1300,7 +1300,7 @@ class DateTime < Date
def to_date() Date.new0(self.class.jd_to_ajd(jd, 0, 0), 0, @sg) end
def to_datetime() self end
- class << self; undef_method :today end
+ class << self; undef_method :today end rescue nil
# Create a new DateTime object representing the current time.
#
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index adba38ed63..b4ed5f5153 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -370,7 +370,7 @@ module FileUtils
#
# # Examples of copying several files to target directory.
# FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
- # FileUtils.cp_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop, :verbose
+ # FileUtils.cp_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop => true, :verbose => true
#
# # If you want to copy all contents of a directory instead of the
# # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index 9421608f85..01856cd2e7 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -38,7 +38,7 @@ module IRB
@inspect_mode = IRB.conf[:INSPECT_MODE]
self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE]
- self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRASER]
+ self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER]
self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER]
self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVAL_HISTORY]
diff --git a/lib/open3.rb b/lib/open3.rb
index 1ddd213f61..69a29aace1 100644
--- a/lib/open3.rb
+++ b/lib/open3.rb
@@ -42,7 +42,7 @@ module Open3
exec(*cmd)
}
- exit!
+ exit!(0)
}
pw[0].close
diff --git a/lib/parsedate.rb b/lib/parsedate.rb
index 405ab46907..2c24ec1636 100644
--- a/lib/parsedate.rb
+++ b/lib/parsedate.rb
@@ -10,6 +10,11 @@ module ParseDate
values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday)
end
- module_function :parsedate
+ def strptime(str, format)
+ Date._strptime(str, format).
+ values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday)
+ end
+
+ module_function :parsedate, :strptime
end
diff --git a/lib/pstore.rb b/lib/pstore.rb
index 50313dcb8f..51cef6e134 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -104,10 +104,14 @@ class PStore
commit_new(file) if FileTest.exist?(new_file)
content = file.read()
else
- file = File.open(@filename, File::RDONLY)
- file.binmode
- file.flock(File::LOCK_SH)
- content = (File.read(new_file) rescue file.read())
+ begin
+ file = File.open(@filename, File::RDONLY)
+ file.binmode
+ file.flock(File::LOCK_SH)
+ content = (File.read(new_file) rescue file.read())
+ rescue Errno::ENOENT
+ content = ""
+ end
end
if content != ""
diff --git a/lib/rdoc/generators/html_generator.rb b/lib/rdoc/generators/html_generator.rb
index f9c72a4df2..d263a14784 100644
--- a/lib/rdoc/generators/html_generator.rb
+++ b/lib/rdoc/generators/html_generator.rb
@@ -314,7 +314,7 @@ module Generators
def collect_methods
list = @context.method_list
unless @options.show_all
- list = list.find_all {|m| m.visibility == :public || m.force_documentation }
+ list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation }
end
@methods = list.collect {|m| HtmlMethod.new(m, self, @options) }
end
@@ -681,13 +681,13 @@ module Generators
res = []
atts.each do |att|
next unless att.section == section
- if att.visibility == :public || @options.show_all
+ if att.visibility == :public || att.visibility == :protected || @options.show_all
entry = {
"name" => CGI.escapeHTML(att.name),
"rw" => att.rw,
"a_desc" => markup(att.comment, true)
}
- unless att.visibility == :public
+ unless att.visibility == :public || att.visibility == :protected
entry["rw"] << "-"
end
res << entry
diff --git a/lib/rdoc/generators/ri_generator.rb b/lib/rdoc/generators/ri_generator.rb
index 8d94579347..c4b4a7e17c 100644
--- a/lib/rdoc/generators/ri_generator.rb
+++ b/lib/rdoc/generators/ri_generator.rb
@@ -172,7 +172,7 @@ module Generators
list = cls.method_list
unless @options.show_all
list = list.find_all do |m|
- m.visibility == :public || m.force_documentation
+ m.visibility == :public || m.visibility == :protected || m.force_documentation
end
end
diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb
index 6c9134fc62..25ce83dd8e 100644
--- a/lib/rdoc/parsers/parse_c.rb
+++ b/lib/rdoc/parsers/parse_c.rb
@@ -174,7 +174,7 @@ module RDoc
# prepare to parse a C file
def initialize(top_level, file_name, body, options, stats)
@known_classes = KNOWN_CLASSES.dup
- @body = handle_ifdefs_in(body)
+ @body = handle_tab_width(handle_ifdefs_in(body))
@options = options
@stats = stats
@top_level = top_level
@@ -187,6 +187,7 @@ module RDoc
def scan
remove_commented_out_lines
do_classes
+ do_constants
do_methods
do_includes
do_aliases
@@ -240,7 +241,7 @@ module RDoc
if @body =~ %r{((?>/\*.*?\*/\s+))
(static\s+)?void\s+Init_#{class_name}\s*\(\)}xmi
comment = $1
- elsif @body =~ %r{Document-(class|module):\s#{class_name}.*?\n((?>.*?\*/))}m
+ elsif @body =~ %r{Document-(class|module):\s#{class_name}\s*?\n((?>.*?\*/))}m
comment = $2
end
class_meth.comment = mangle_comment(comment) if comment
@@ -249,13 +250,13 @@ module RDoc
############################################################
def do_classes
- @body.scan(/(\w+)\s* = \s*rb_define_module\(\s*"(\w+)"\s*\)/mx) do
+ @body.scan(/(\w+)\s* = \s*rb_define_module\s*\(\s*"(\w+)"\s*\)/mx) do
|var_name, class_name|
handle_class_module(var_name, "module", class_name, nil, nil)
end
# The '.' lets us handle SWIG-generated files
- @body.scan(/([\w\.]+)\s* = \s*rb_define_class
+ @body.scan(/([\w\.]+)\s* = \s*rb_define_class\s*
\(
\s*"(\w+)",
\s*(\w+)\s*
@@ -265,7 +266,7 @@ module RDoc
handle_class_module(var_name, "class", class_name, parent, nil)
end
- @body.scan(/(\w+)\s*=\s*boot_defclass\(\s*"(\w+?)",\s*(\w+?)\)/) do
+ @body.scan(/(\w+)\s*=\s*boot_defclass\s*\(\s*"(\w+?)",\s*(\w+?)\s*\)/) do
|var_name, class_name, parent|
parent = nil if parent == "0"
handle_class_module(var_name, "class", class_name, parent, nil)
@@ -281,18 +282,40 @@ module RDoc
handle_class_module(var_name, "module", class_name, nil, in_module)
end
- @body.scan(/([\w\.]+)\s* = \s*rb_define_class_under
+ @body.scan(/([\w\.]+)\s* = \s*rb_define_class_under\s*
\(
\s*(\w+),
\s*"(\w+)",
\s*(\w+)\s*
- \)/mx) do
+ \s*\)/mx) do
|var_name, in_module, class_name, parent|
handle_class_module(var_name, "class", class_name, parent, in_module)
end
end
+
+ ###########################################################
+
+ def do_constants
+ @body.scan(%r{\Wrb_define_
+ (
+ variable |
+ readonly_variable |
+ const |
+ global_const |
+ )
+ \s*\(
+ (?:\s*(\w+),)?
+ \s*"(\w+)",
+ \s*(.*?)\s*\)\s*;
+ }xm) do
+
+ |type, var_name, const_name, definition|
+ var_name = "rb_cObject" if !var_name or var_name == "rb_mKernel"
+ handle_constants(type, var_name, const_name, definition)
+ end
+ end
############################################################
@@ -305,7 +328,7 @@ module RDoc
module_function |
private_method
)
- \(\s*([\w\.]+),
+ \s*\(\s*([\w\.]+),
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
\s*(-?\w+)\s*\)
@@ -325,7 +348,21 @@ module RDoc
meth_body, param_count, source_file)
end
- @body.scan(%r{rb_define_global_function\(
+ @body.scan(%r{rb_define_attr\(
+ \s*([\w\.]+),
+ \s*"([^"]+)",
+ \s*(\d+),
+ \s*(\d+)\s*\);
+ }xm) do #"
+ |var_name, attr_name, attr_reader, attr_writer|
+
+ #var_name = "rb_cObject" if var_name == "rb_mKernel"
+ handle_attr(var_name, attr_name,
+ attr_reader.to_i != 0,
+ attr_writer.to_i != 0)
+ end
+
+ @body.scan(%r{rb_define_global_function\s*\(
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
\s*(-?\w+)\s*\)
@@ -336,7 +373,7 @@ module RDoc
meth_body, param_count, source_file)
end
- @body.scan(/define_filetest_function\(
+ @body.scan(/define_filetest_function\s*\(
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
\s*(-?\w+)\s*\)/xm) do #"
@@ -350,7 +387,7 @@ module RDoc
############################################################
def do_aliases
- @body.scan(%r{rb_define_alias\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do
+ @body.scan(%r{rb_define_alias\s*\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do
|var_name, new_name, old_name|
@stats.num_methods += 1
class_name = @known_classes[var_name] || var_name
@@ -362,6 +399,83 @@ module RDoc
############################################################
+ def handle_constants(type, var_name, const_name, definition)
+ #@stats.num_constants += 1
+ class_name = @known_classes[var_name]
+
+ return unless class_name
+
+ class_obj = find_class(var_name, class_name)
+
+ unless class_obj
+ $stderr.puts("Enclosing class/module '#{const_name}' for not known")
+ return
+ end
+
+ comment = find_const_comment(type, const_name)
+
+ con = Constant.new(const_name, definition, mangle_comment(comment))
+ class_obj.add_constant(con)
+ end
+
+ ###########################################################
+
+ def find_const_comment(type, const_name)
+ if @body =~ %r{((?>/\*.*?\*/\s+))
+ rb_define_#{type}\((?:\s*(\w+),)?\s*"#{const_name}"\s*,.*?\)\s*;}xmi
+ $1
+ elsif @body =~ %r{Document-(?:const|global|variable):\s#{const_name}\s*?\n((?>.*?\*/))}m
+ $1
+ else
+ ''
+ end
+ end
+
+ ###########################################################
+
+ def handle_attr(var_name, attr_name, reader, writer)
+ rw = ''
+ if reader
+ #@stats.num_methods += 1
+ rw << 'R'
+ end
+ if writer
+ #@stats.num_methods += 1
+ rw << 'W'
+ end
+
+ class_name = @known_classes[var_name]
+
+ return unless class_name
+
+ class_obj = find_class(var_name, class_name)
+
+ if class_obj
+ comment = find_attr_comment(attr_name)
+ unless comment.empty?
+ comment = mangle_comment(comment)
+ end
+ att = Attr.new('', attr_name, rw, comment)
+ class_obj.add_attribute(att)
+ end
+
+ end
+
+ ###########################################################
+
+ def find_attr_comment(attr_name)
+ if @body =~ %r{((?>/\*.*?\*/\s+))
+ rb_define_attr\((?:\s*(\w+),)?\s*"#{attr_name}"\s*,.*?\)\s*;}xmi
+ $1
+ elsif @body =~ %r{Document-attr:\s#{attr_name}\s*?\n((?>.*?\*/))}m
+ $1
+ else
+ ''
+ end
+ end
+
+ ###########################################################
+
def handle_method(type, var_name, meth_name,
meth_body, param_count, source_file = nil)
@stats.num_methods += 1
@@ -469,12 +583,10 @@ module RDoc
############################################################
def find_override_comment(meth_name)
- comment = nil
name = Regexp.escape(meth_name)
- if @body =~ %r{Document-method:\s#{name}.*?\n((?>.*?\*/))}m
- comment = $1
+ if @body =~ %r{Document-method:\s#{name}\s*?\n((?>.*?\*/))}m
+ $1
end
- comment
end
############################################################
@@ -482,7 +594,7 @@ module RDoc
# Look for includes of the form
# rb_include_module(rb_cArray, rb_mEnumerable);
def do_includes
- @body.scan(/rb_include_module\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
+ @body.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
if cls = @classes[c]
m = KNOWN_CLASSES[m] || m
cls.add_include(Include.new(m, ""))
@@ -512,6 +624,18 @@ module RDoc
@classes[raw_name]
end
+ def handle_tab_width(body)
+ if /\t/ =~ body
+ tab_width = Options.instance.tab_width
+ body.split(/\n/).map do |line|
+ 1 while line.gsub!(/\t+/) { ' ' * (tab_width*$&.length - $`.length % tab_width)} && $~ #`
+ line
+ end .join("\n")
+ else
+ body
+ end
+ end
+
# Remove #ifdefs that would otherwise confuse us
def handle_ifdefs_in(body)
diff --git a/lib/rdoc/parsers/parse_rb.rb b/lib/rdoc/parsers/parse_rb.rb
index 15b3484cb7..8e91c01e61 100644
--- a/lib/rdoc/parsers/parse_rb.rb
+++ b/lib/rdoc/parsers/parse_rb.rb
@@ -1883,6 +1883,7 @@ module RDoc
name_t = get_tk
back_tk = skip_tkspace
meth = nil
+ added_container = false
dot = get_tk
if dot.kind_of?(TkDOT) or dot.kind_of?(TkCOLON2)
@@ -1897,8 +1898,21 @@ module RDoc
prev_container = container
container = container.find_module_named(name_t.name)
if !container
- warn("Couldn't find #{name_t.name}. Assuming it's a module")
- container = prev_container.add_module(NormalModule, name_t.name)
+ added_container = true
+ obj = name_t.name.split("::").inject(Object) do |state, item|
+ state.const_get(item)
+ end rescue nil
+
+ type = obj.class == Class ? NormalClass : NormalModule
+ if not [Class, Module].include?(obj.class)
+ warn("Couldn't find #{name_t.name}. Assuming it's a module")
+ end
+
+ if type == NormalClass then
+ container = prev_container.add_class(type, name_t.name, obj.superclass.name)
+ else
+ container = prev_container.add_module(type, name_t.name)
+ end
end
else
# warn("Unexpected token '#{name_t2.inspect}'")
@@ -1940,7 +1954,9 @@ module RDoc
parse_method_parameters(meth)
if meth.document_self
- container.add_method(meth)
+ container.add_method(meth)
+ elsif added_container
+ container.document_self = false
end
# Having now read the method parameters and documentation modifiers, we
diff --git a/lib/rdoc/parsers/parse_simple.rb b/lib/rdoc/parsers/parse_simple.rb
index b01104574e..3f1a546964 100644
--- a/lib/rdoc/parsers/parse_simple.rb
+++ b/lib/rdoc/parsers/parse_simple.rb
@@ -30,8 +30,12 @@ module RDoc
def scan
# @body.gsub(/^(\s\n)+/, '')
- @top_level.comment = @body
+ @top_level.comment = remove_private_comments(@body)
@top_level
end
+
+ def remove_private_comments(comment)
+ comment.gsub(/^--.*?^\+\+/m, '').sub(/^--.*/m, '')
+ end
end
end
diff --git a/lib/rexml/document.rb b/lib/rexml/document.rb
index a7f056ad3f..39360d4f4a 100644
--- a/lib/rexml/document.rb
+++ b/lib/rexml/document.rb
@@ -156,12 +156,12 @@ module REXML
# unable to parse proper XML, we have to provide a hack to generate XML
# that IE's limited abilities can handle. This hack inserts a space
# before the /> on empty tags. Defaults to false
- def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
+ def write( output=$stdout, indent_level=-1, transitive=false, ie_hack=false )
output = Output.new( output, xml_decl.encoding ) if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
@children.each { |node|
- indent( output, indent ) if node.node_type == :element
- if node.write( output, indent, transitive, ie_hack )
- output << "\n" unless indent<0 or node == @children[-1]
+ indent( output, indent_level ) if node.node_type == :element
+ if node.write( output, indent_level, transitive, ie_hack )
+ output << "\n" unless indent_level<0 or node == @children[-1]
end
}
end
diff --git a/lib/rexml/element.rb b/lib/rexml/element.rb
index b76c0179c7..e18f0b28c7 100644
--- a/lib/rexml/element.rb
+++ b/lib/rexml/element.rb
@@ -199,7 +199,7 @@ module REXML
# b.namespace("y") # -> '2'
def namespace(prefix=nil)
if prefix.nil?
- prefix = prefix()
+ prefix = self.prefix()
end
if prefix == ''
prefix = "xmlns"
diff --git a/lib/rexml/instruction.rb b/lib/rexml/instruction.rb
index 0b770d4b3d..ebd868c95c 100644
--- a/lib/rexml/instruction.rb
+++ b/lib/rexml/instruction.rb
@@ -38,8 +38,8 @@ module REXML
Instruction.new self
end
- def write writer, indent=-1, transitive=false, ie_hack=false
- indent(writer, indent)
+ def write writer, indent_level=-1, transitive=false, ie_hack=false
+ indent(writer, indent_level)
writer << START.sub(/\\/u, '')
writer << @target
writer << ' '
diff --git a/lib/rexml/xmldecl.rb b/lib/rexml/xmldecl.rb
index 3f90e0160f..df2cbf0060 100644
--- a/lib/rexml/xmldecl.rb
+++ b/lib/rexml/xmldecl.rb
@@ -2,71 +2,71 @@ require 'rexml/encoding'
require 'rexml/source'
module REXML
- # NEEDS DOCUMENTATION
- class XMLDecl < Child
- include Encoding
+ # NEEDS DOCUMENTATION
+ class XMLDecl < Child
+ include Encoding
- DEFAULT_VERSION = "1.0";
- DEFAULT_ENCODING = "UTF-8";
- DEFAULT_STANDALONE = "no";
- START = '<\?xml';
- STOP = '\?>';
+ DEFAULT_VERSION = "1.0";
+ DEFAULT_ENCODING = "UTF-8";
+ DEFAULT_STANDALONE = "no";
+ START = '<\?xml';
+ STOP = '\?>';
- attr_accessor :version, :standalone
+ attr_accessor :version, :standalone
attr_reader :writeencoding
- def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil)
+ def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil)
@writethis = true
@writeencoding = !encoding.nil?
- if version.kind_of? XMLDecl
- super()
- @version = version.version
- self.encoding = version.encoding
+ if version.kind_of? XMLDecl
+ super()
+ @version = version.version
+ self.encoding = version.encoding
@writeencoding = version.writeencoding
- @standalone = version.standalone
- else
- super()
- @version = version
- self.encoding = encoding
- @standalone = standalone
- end
- @version = DEFAULT_VERSION if @version.nil?
- end
+ @standalone = version.standalone
+ else
+ super()
+ @version = version
+ self.encoding = encoding
+ @standalone = standalone
+ end
+ @version = DEFAULT_VERSION if @version.nil?
+ end
- def clone
- XMLDecl.new(self)
- end
+ def clone
+ XMLDecl.new(self)
+ end
- def write writer, indent=-1, transitive=false, ie_hack=false
+ def write writer, indent_level=-1, transitive=false, ie_hack=false
return nil unless @writethis or writer.kind_of? Output
- indent( writer, indent )
- writer << START.sub(/\\/u, '')
+ indent( writer, indent_level )
+ writer << START.sub(/\\/u, '')
if writer.kind_of? Output
writer << " #{content writer.encoding}"
else
writer << " #{content encoding}"
end
- writer << STOP.sub(/\\/u, '')
- end
+ writer << STOP.sub(/\\/u, '')
+ end
- def ==( other )
- other.kind_of?(XMLDecl) and
- other.version == @version and
- other.encoding == self.encoding and
- other.standalone == @standalone
- end
+ def ==( other )
+ other.kind_of?(XMLDecl) and
+ other.version == @version and
+ other.encoding == self.encoding and
+ other.standalone == @standalone
+ end
- def xmldecl version, encoding, standalone
- @version = version
- self.encoding = encoding
- @standalone = standalone
- end
+ def xmldecl version, encoding, standalone
+ @version = version
+ self.encoding = encoding
+ @standalone = standalone
+ end
- def node_type
- :xmldecl
- end
+ def node_type
+ :xmldecl
+ end
- alias :stand_alone? :standalone
+ alias :stand_alone? :standalone
alias :old_enc= :encoding=
def encoding=( enc )
@@ -94,12 +94,12 @@ module REXML
@writethis = true
end
- private
- def content(enc)
- rv = "version='#@version'"
- rv << " encoding='#{enc}'" if @writeencoding || enc !~ /utf-8/i
- rv << " standalone='#@standalone'" if @standalone
- rv
- end
- end
+ private
+ def content(enc)
+ rv = "version='#@version'"
+ rv << " encoding='#{enc}'" if @writeencoding || enc !~ /utf-8/i
+ rv << " standalone='#@standalone'" if @standalone
+ rv
+ end
+ end
end
diff --git a/lib/set.rb b/lib/set.rb
index 8364d4a072..b8dd2ca569 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -438,6 +438,11 @@ class SortedSet < Set
def setup # :nodoc:
@@setup and return
+ module_eval {
+ # a hack to shut up warning
+ alias old_init initialize
+ remove_method :old_init
+ }
begin
require 'rbtree'
diff --git a/lib/time.rb b/lib/time.rb
index e0d831d3b0..ce3614bfce 100644
--- a/lib/time.rb
+++ b/lib/time.rb
@@ -94,6 +94,37 @@ class Time
end
private :zone_utc?
+ def make_time(year, mon, day, hour, min, sec, zone, now)
+ if now
+ begin
+ break if year; year = now.year
+ break if mon; mon = now.mon
+ break if day; day = now.day
+ break if hour; hour = now.hour
+ break if min; min = now.min
+ break if sec; sec = now.sec
+ end until true
+ end
+
+ year ||= 1970
+ mon ||= 1
+ day ||= 1
+ hour ||= 0
+ min ||= 0
+ sec ||= 0
+
+ off = nil
+ off = zone_offset(zone, year) if zone
+
+ if off
+ t = Time.utc(year, mon, day, hour, min, sec) - off
+ t.localtime if !zone_utc?(zone)
+ t
+ else
+ Time.local(year, mon, day, hour, min, sec)
+ end
+ end
+
#
# Parses +date+ using ParseDate.parsedate and converts it to a Time object.
#
@@ -147,35 +178,20 @@ class Time
def parse(date, now=Time.now)
year, mon, day, hour, min, sec, zone, _ = ParseDate.parsedate(date)
year = yield(year) if year && block_given?
+ make_time(year, mon, day, hour, min, sec, zone, now)
+ end
- if now
- begin
- break if year; year = now.year
- break if mon; mon = now.mon
- break if day; day = now.day
- break if hour; hour = now.hour
- break if min; min = now.min
- break if sec; sec = now.sec
- end until true
- end
-
- year ||= 1970
- mon ||= 1
- day ||= 1
- hour ||= 0
- min ||= 0
- sec ||= 0
-
- off = nil
- off = zone_offset(zone, year) if zone
-
- if off
- t = Time.utc(year, mon, day, hour, min, sec) - off
- t.localtime if !zone_utc?(zone)
- t
- else
- Time.local(year, mon, day, hour, min, sec)
- end
+ #
+ # Parses +date+ using ParseDate.strptime and converts it to a Time object.
+ #
+ # If a block is given, the year described in +date+ is converted by the
+ # block. For example:
+ #
+ # Time.parse(...) {|y| y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}
+ def strptime(date, format, now=Time.now)
+ year, mon, day, hour, min, sec, zone, _ = ParseDate.strptime(date, format)
+ year = yield(year) if year && block_given?
+ make_time(year, mon, day, hour, min, sec, zone, now)
end
MonthValue = {
diff --git a/lib/timeout.rb b/lib/timeout.rb
index 7e3ee81ed0..36811a1040 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -1,38 +1,39 @@
+# = timeout.rb
#
-# timeout.rb -- execution timeout
+# execution timeout
#
-# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
-# Copyright (C) 2000 Information-technology Promotion Agency, Japan
-#
-#= SYNOPSIS
+# = Synopsis
#
# require 'timeout'
-# status = timeout(5) {
-# # something may take time
+# status = Timeout::timeout(5) {
+# # Something that should be interrupted if it takes too much time...
# }
#
-#= DESCRIPTION
-#
-# timeout executes the block. If the block execution terminates successfully
-# before timeout, it returns true. If not, it terminates the execution and
-# raise TimeoutError exception.
-#
-#== Parameters
-#
-# : timout
+# = Description
#
-# The time in seconds to wait for block termination.
+# A way of performing a potentially long-running operation in a thread, and terminating
+# it's execution if it hasn't finished by a fixed amount of time.
#
-# : [exception]
+# Previous versions of timeout didn't provide use a module for namespace. This version
+# provides both Timeout.timeout, and a backwards-compatible #timeout.
#
-# The exception class to be raised on timeout.
+# = Copyright
#
-#=end
+# Copyright:: (C) 2000 Network Applied Communication Laboratory, Inc.
+# Copyright:: (C) 2000 Information-technology Promotion Agency, Japan
module Timeout
+ # Raised by Timeout#timeout when the block times out.
class Error<Interrupt
end
+ # Executes the method's block. If the block execution terminates before +sec+
+ # seconds has passed, it returns true. If not, it terminates the execution
+ # and raises +exception+ (which defaults to Timeout::Error).
+ #
+ # Note that this is both a method of module Timeout, so you can 'include Timeout'
+ # into your classes so they have a #timeout method, as well as a module method,
+ # so you can call it directly as Timeout.timeout().
def timeout(sec, exception=Error)
return yield if sec == nil or sec.zero?
raise ThreadError, "timeout within critical session" if Thread.critical
@@ -48,13 +49,22 @@ module Timeout
y.kill if y and y.alive?
end
end
+
module_function :timeout
end
-# compatible
+# Identical to:
+#
+# Timeout::timeout(n, e, &block).
+#
+# Defined for backwards compatibility with earlier versions of timeout.rb, see
+# Timeout#timeout.
def timeout(n, e=Timeout::Error, &block)
Timeout::timeout(n, e, &block)
end
+
+# Another name for Timeout::Error, defined for backwards compatibility with
+# earlier versions of timeout.rb.
TimeoutError = Timeout::Error
if __FILE__ == $0
diff --git a/lib/wsdl/soap/definitions.rb b/lib/wsdl/soap/definitions.rb
index 2f6e7e19f0..fced82bdec 100644
--- a/lib/wsdl/soap/definitions.rb
+++ b/lib/wsdl/soap/definitions.rb
@@ -77,8 +77,8 @@ class Definitions < Info
def collect_faulttypes
result = []
- collect_fault_messages.each do |message|
- parts = message(message).parts
+ collect_fault_messages.each do |m|
+ parts = message(m).parts
if parts.size != 1
raise RuntimeError.new("Expecting fault message to have only 1 part.")
end
diff --git a/lib/xmlrpc/parser.rb b/lib/xmlrpc/parser.rb
index 2062ec1f05..931f93583b 100644
--- a/lib/xmlrpc/parser.rb
+++ b/lib/xmlrpc/parser.rb
@@ -51,7 +51,7 @@ end # module NQXML
module XMLRPC
- class FaultException < Exception
+ class FaultException < StandardError
attr_reader :faultCode, :faultString
def initialize(faultCode, faultString)