Skip to content

Commit

Permalink
Fix warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
philr committed Aug 8, 2014
1 parent 55bd66a commit b51be04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
29 changes: 11 additions & 18 deletions lib/tzinfo/data/tzdataparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@ module Data
#
# @private
module TZDataParserUtils #:nodoc:

begin
Encoding
SUPPORTS_ENCODING = true
rescue NameError
SUPPORTS_ENCODING = false
end

if SUPPORTS_ENCODING
# Wrapper for File.open that supports passing hash options for specifying
# encodings on Ruby 1.9+. The options are ignored on earlier versions of
# Ruby.
if RUBY_VERSION =~ /\A1\.[0-8]\./
def open_file(file_name, mode, opts, &block)
File.open(file_name, mode, opts, &block)
File.open(file_name, mode, &block)
end
else
def open_file(file_name, mode, opts, &block)
File.open(file_name, mode, &block)
File.open(file_name, mode, opts, &block)
end
end

Expand Down Expand Up @@ -581,19 +576,17 @@ def create_file(output_dir)
FileUtils.mkdir_p(dir)

open_file(File.join(output_dir, 'definitions', @name_elements.join(File::SEPARATOR)) + '.rb', 'w', :external_encoding => 'UTF-8', :universal_newline => true) do |file|

file.instance_variable_set(:@tz_indent, 0)

def file.indent(by)
if @tz_indent
@tz_indent += by
else
@tz_indent = by
end
@tz_indent += by
end

def file.puts(s)
super("#{' ' * (@tz_indent || 0)}#{s}")
super("#{' ' * @tz_indent}#{s}")
end

file.puts('# encoding: UTF-8')
file.puts('')
file.puts('# This file contains data derived from the IANA Time Zone Database')
Expand Down
23 changes: 8 additions & 15 deletions test/test_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,14 @@ def assert_nothing_raised(msg = nil)
assert(false, full_message)
end
end
end

begin
Encoding
SUPPORTS_ENCODING = true
rescue NameError
SUPPORTS_ENCODING = false
end

if SUPPORTS_ENCODING
def open_file(file_name, mode, opts, &block)
File.open(file_name, mode, opts, &block)
end
else
def open_file(file_name, mode, opts, &block)
File.open(file_name, mode, &block)
if RUBY_VERSION =~ /\A1\.[0-8]\./
def open_file(file_name, mode, opts, &block)
File.open(file_name, mode, &block)
end
else
def open_file(file_name, mode, opts, &block)
File.open(file_name, mode, opts, &block)
end
end
end

0 comments on commit b51be04

Please sign in to comment.