Skip to content

Commit

Permalink
Merge pull request #111 from matthutchinson/fix-ruby-2-4-issues
Browse files Browse the repository at this point in the history
Fix Ruby 2.4 issues
  • Loading branch information
davetron5000 authored Jan 2, 2017
2 parents c9602c4 + 6c1f06d commit 7a6c482
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
13 changes: 7 additions & 6 deletions lib/methadone/cli_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Methadone
# is redirected to a file, a better timestamped logging format is used
#
# You can customize this in several ways:
#
#
# * You can override the devices used by passing different devices to the constructor
# * You can adjust the level of message that goes to the error logger via error_level=
# * You can adjust the format for messages to the error logger separately via error_formatter=
Expand All @@ -33,7 +33,7 @@ module Methadone
# logger.debug("Starting up") # => only the standard output gets this
# logger.warn("careful!") # => only the standard OUTPUT gets this
# logger.error("Something went wrong!") # => only the standard error gets this
#
#
# logger = CLILogger.new('logfile.txt')
# logger.debug("Starting up") # => logfile.txt gets this
# logger.error("Something went wrong!") # => BOTH logfile.txt AND the standard error get this
Expand All @@ -43,7 +43,7 @@ class CLILogger < Logger
}

# Helper to proxy methods to the super class AND to the internal error logger
#
#
# +symbol+:: Symbol for name of the method to proxy
def self.proxy_method(symbol) #:nodoc:
old_name = "old_#{symbol}".to_sym
Expand All @@ -58,7 +58,7 @@ def self.proxy_method(symbol) #:nodoc:
proxy_method :'datetime_format='

def add(severity, message = nil, progname = nil, &block) #:nodoc:
if @split_logs
if @split_logs
unless severity >= @stderr_logger.level
super(severity,message,progname,&block)
end
Expand All @@ -67,7 +67,7 @@ def add(severity, message = nil, progname = nil, &block) #:nodoc:
end
@stderr_logger.add(severity,message,progname,&block)
end

DEFAULT_ERROR_LEVEL = Logger::Severity::WARN

# A logger that logs error-type messages to a second device; useful
Expand All @@ -82,9 +82,10 @@ def add(severity, message = nil, progname = nil, &block) #:nodoc:
# +log_device+:: device where all log messages should go, based on level
# +error_device+:: device where all error messages should go. By default, this is Logger::Severity::WARN
def initialize(log_device=$stdout,error_device=$stderr)
super(log_device)
@stderr_logger = Logger.new(error_device)

super(log_device)

log_device_tty = tty?(log_device)
error_device_tty = tty?(error_device)

Expand Down
42 changes: 21 additions & 21 deletions lib/methadone/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ module Methadone
# You also get a more expedient interface to OptionParser as well
# as checking for required arguments to your app. For example, if
# we want our app to accept a negatable switch named "switch", a flag
# named "flag", and two arguments "needed" (which is required)
# named "flag", and two arguments "needed" (which is required)
# and "maybe" which is optional, we can do the following:
#
# #!/usr/bin/env ruby
#
#
# require 'methadone'
#
#
# class App
# include Methadone::Main
# include Methadone::CLILogging
#
#
# main do |needed, maybe|
# options[:switch] => true or false, based on command line
# options[:flag] => value of flag passed on command line
# end
#
#
# # Proxy to an OptionParser instance's on method
# on("--[no]-switch")
# on("--flag VALUE")
Expand All @@ -52,7 +52,7 @@ module Methadone
#
# Our app then acts as follows:
#
# $ our_app
# $ our_app
# # => parse error: 'needed' is required
# $ our_app foo
# # => succeeds; "maybe" in main is nil
Expand Down Expand Up @@ -81,7 +81,7 @@ def self.included(k)
# Declare the main method for your app.
# This allows you to specify the general logic of your
# app at the top of your bin file, but can rely on any methods
# or other code that you define later.
# or other code that you define later.
#
# For example, suppose you want to process a set of files, but
# wish to determine that list from another method to keep your
Expand Down Expand Up @@ -111,7 +111,7 @@ def self.included(k)
# *Note*: #go! will modify +ARGV+ so any unparsed arguments that you do *not* declare as arguments
# to #main will essentially be unavailable. I consider this a bug, and it should be changed/fixed in
# a future version.
#
#
# To run this method, call #go!
def main(&block)
@main_block = block
Expand Down Expand Up @@ -165,7 +165,7 @@ def go!
opts.parse!
opts.check_args!
result = call_main
if result.kind_of? Fixnum
if result.kind_of? Integer
exit result
else
exit 0
Expand Down Expand Up @@ -299,7 +299,7 @@ def version(version,version_options={})
end
version_options[:custom_docs] ||= "Show help/version info"
version_options[:format] ||= "%s version %s"
opts.on("--version",version_options[:custom_docs]) do
opts.on("--version",version_options[:custom_docs]) do
if version_options[:compact]
puts version_options[:format] % [::File.basename($0),version]
else
Expand Down Expand Up @@ -352,7 +352,7 @@ def set_defaults_from_env_var

def set_defaults_from_rc_file
if @rc_file && File.exists?(@rc_file)
File.open(@rc_file) do |file|
File.open(@rc_file) do |file|
parsed = begin
YAML::load(file)
rescue => ex
Expand Down Expand Up @@ -461,9 +461,9 @@ def on(*args,&block)
else
opt_names = option_names(*args)
@option_parser.on(*args) do |value|
opt_names.each do |name|
@options[name] = value
@options[name.to_s] = value
opt_names.each do |name|
@options[name] = value
@options[name.to_s] = value
end
end
end
Expand Down Expand Up @@ -494,7 +494,7 @@ def description(desc)
set_banner
end

# Defers all calls save #on to
# Defers all calls save #on to
# the underlying OptionParser instance
def method_missing(sym,*args,&block)
@option_parser.send(sym,*args,&block)
Expand Down Expand Up @@ -528,7 +528,7 @@ def post_setup
private

def document_help
@option_parser.on("-h","--help","Show command line help") do
@option_parser.on("-h","--help","Show command line help") do
puts @option_parser.to_s
exit 0
end
Expand All @@ -547,10 +547,10 @@ def add_default_value_to_docstring(*args)
end

def option_names_from(args)
args.select(&STRINGS_ONLY).select { |_|
_ =~ /^\-/
}.map { |_|
_.gsub(/^\-+/,'').gsub(/\s.*$/,'')
args.select(&STRINGS_ONLY).select { |_|
_ =~ /^\-/
}.map { |_|
_.gsub(/^\-+/,'').gsub(/\s.*$/,'')
}
end

Expand All @@ -559,7 +559,7 @@ def set_banner
new_banner="Usage: #{::File.basename($0)}"
new_banner += " [options]" if @accept_options
unless @args.empty?
new_banner += " "
new_banner += " "
new_banner += @args.map { |arg|
if @arg_options[arg].include? :any
"[#{arg.to_s}...]"
Expand Down
2 changes: 1 addition & 1 deletion lib/methadone/process_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def derive_exitstatus(status)
else
status
end
if status.kind_of? Fixnum
if status.kind_of? Integer
status
elsif status
0
Expand Down
4 changes: 2 additions & 2 deletions methadone.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.add_dependency("bundler")
s.add_development_dependency("rake")
s.add_development_dependency("rdoc","~> 3.9")
s.add_development_dependency("rdoc","~> 5.0")
s.add_development_dependency("cucumber")
s.add_development_dependency("aruba", "0.5.1")
s.add_development_dependency("simplecov", "~> 0.5")
s.add_development_dependency("clean_test")
s.add_development_dependency("mocha", "0.13.2")
s.add_development_dependency("sdoc")
s.add_development_dependency("sdoc", "1.0.0.rc1")
s.add_development_dependency("rspec", "~> 3")
s.add_development_dependency("i18n", "= 0.6.1")
end
2 changes: 1 addition & 1 deletion test/test_sh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def initialize(exitcode)

def run_command(command)
@command = command
if @exitcode.kind_of? Fixnum
if @exitcode.kind_of? Integer
[any_string,any_string,OpenStruct.new(:exitstatus => @exitcode)]
else
[any_string,any_string,@exitcode]
Expand Down

0 comments on commit 7a6c482

Please sign in to comment.