Skip to content

Cleanup code targeted Ruby 1.8 #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/rdoc/markup/to_bs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def convert_special special
# Adds bold or underline mixed with backspaces

def convert_string string
return string unless string.respond_to? :chars # your ruby is lame
return string unless @in_b or @in_em
chars = if @in_b then
string.chars.map do |char| "#{char}\b#{char}" end
Expand All @@ -76,4 +75,3 @@ def convert_string string
end

end

25 changes: 7 additions & 18 deletions lib/rdoc/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,15 @@ def self.binary?(file)

s = File.read(file, 1024) or return false

have_encoding = s.respond_to? :encoding

return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")

if have_encoding then
mode = "r"
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
mode = "rb:#{encoding}" if encoding
s = File.open(file, mode) {|f| f.gets(nil, 1024)}

not s.valid_encoding?
else
if 0.respond_to? :fdiv then
s.count("\x00-\x7F", "^ -~\t\r\n").fdiv(s.size) > 0.3
else # HACK 1.8.6
(s.count("\x00-\x7F", "^ -~\t\r\n").to_f / s.size) > 0.3
end
end
mode = "r"
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
mode = "rb:#{encoding}" if encoding
s = File.open(file, mode) {|f| f.gets(nil, 1024)}

not s.valid_encoding?
end

##
Expand Down Expand Up @@ -308,4 +298,3 @@ def initialize top_level, file_name, content, options, stats
require 'rdoc/parser/markdown'
require 'rdoc/parser/rd'
require 'rdoc/parser/ruby'

2 changes: 1 addition & 1 deletion lib/rdoc/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def document options
@last_modified = setup_output_dir @options.op_dir, @options.force_update
end

@store.encoding = @options.encoding if @options.respond_to? :encoding
@store.encoding = @options.encoding
@store.dry_run = @options.dry_run
@store.main = @options.main_page
@store.title = @options.title
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/rubygems_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def generate
@rdoc.options = options

store = RDoc::Store.new
store.encoding = options.encoding if options.respond_to? :encoding
store.encoding = options.encoding
store.dry_run = options.dry_run
store.main = options.main_page
store.title = options.title
Expand Down
12 changes: 2 additions & 10 deletions lib/rdoc/stats/normal.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# frozen_string_literal: false
begin
require 'io/console/size'
rescue LoadError
end
require 'io/console/size'

##
# Stats printer that prints just the files being documented with a progress
Expand All @@ -26,11 +23,7 @@ def print_file files_so_far, filename

# Print a progress bar, but make sure it fits on a single line. Filename
# will be truncated if necessary.
terminal_width = if defined?(IO) && IO.respond_to?(:console_size)
IO.console_size[1].to_i.nonzero? || 80
else
80
end
terminal_width = IO.console_size[1].to_i.nonzero? || 80
max_filename_size = terminal_width - progress_bar.size

if filename.size > max_filename_size then
Expand All @@ -57,4 +50,3 @@ def done_adding # :nodoc:
end

end

7 changes: 1 addition & 6 deletions lib/rdoc/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,7 @@ def method_file klass_name, method_name
method_name =~ /#(.*)/
method_type = $1 ? 'i' : 'c'
method_name = $1 if $1

method_name = if ''.respond_to? :ord then
method_name.gsub(/\W/) { "%%%02x" % $&[0].ord }
else
method_name.gsub(/\W/) { "%%%02x" % $&[0] }
end
method_name = method_name.gsub(/\W/) { "%%%02x" % $&[0].ord }

File.join class_path(klass_name), "#{method_name}-#{method_type}.ri"
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_rdoc_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_class_for_forbidden
end
io
end
tf.close! if tf.respond_to? :close!
tf.close!
end

def test_class_for_modeline
Expand Down
2 changes: 1 addition & 1 deletion test/test_rdoc_rd_block_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_parse_include_subtree
assert_equal expected, parse(str)
io
end
tf.close! if tf.respond_to? :close!
tf.close!
end

def test_parse_heading
Expand Down
6 changes: 3 additions & 3 deletions test/test_rdoc_rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def test_parse_file_encoding
assert_equal Encoding::ISO_8859_1, top_level.absolute_name.encoding
io
end
tf.close! if tf.respond_to? :close!
tf.close!
end

def test_parse_file_forbidden
Expand Down Expand Up @@ -290,7 +290,7 @@ def test_parse_file_forbidden
end
io
end
tf.close! if tf.respond_to? :close!
tf.close!
end

def test_remove_unparseable
Expand Down Expand Up @@ -398,7 +398,7 @@ def test_setup_output_dir_exists_file
e.message)
tempfile
end
tf.close! if tf.respond_to? :close!
tf.close!
end

def test_setup_output_dir_exists_not_rdoc
Expand Down