mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
rubocop: fix offences of the Style/IfUnlessModifier cop
This commit is contained in:
parent
8ea5b6e0aa
commit
39fa8a9fc6
45 changed files with 81 additions and 248 deletions
|
@ -274,11 +274,6 @@ Style/IfInsideElse:
|
|||
- 'lib/pry/slop/commands.rb'
|
||||
- 'lib/pry/slop/option.rb'
|
||||
|
||||
# Offense count: 79
|
||||
# Cop supports --auto-correct.
|
||||
Style/IfUnlessModifier:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: InverseMethods, InverseBlocks.
|
||||
|
|
4
Gemfile
4
Gemfile
|
@ -7,9 +7,7 @@ group :development do
|
|||
gem 'yard'
|
||||
|
||||
# Rubocop supports only >=2.2.0
|
||||
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2.0')
|
||||
gem 'rubocop', '= 0.65.0', require: false
|
||||
end
|
||||
gem 'rubocop', '= 0.65.0', require: false if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2.0')
|
||||
end
|
||||
|
||||
group :test do
|
||||
|
|
|
@ -75,9 +75,7 @@ class Pry
|
|||
end
|
||||
|
||||
DEFAULT_SYSTEM = proc do |output, cmd, _|
|
||||
if !system(cmd)
|
||||
output.puts "Error: there was a problem executing system command: #{cmd}"
|
||||
end
|
||||
output.puts "Error: there was a problem executing system command: #{cmd}" if !system(cmd)
|
||||
end
|
||||
|
||||
# This is to keep from breaking under Rails 3.2 for people who are doing that
|
||||
|
|
|
@ -55,9 +55,7 @@ class Pry
|
|||
end
|
||||
|
||||
def parse_options(args = ARGV)
|
||||
unless options
|
||||
raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options."
|
||||
end
|
||||
raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options." unless options
|
||||
|
||||
@pass_argv = args.index { |cli_arg| %w[- --].include?(cli_arg) }
|
||||
if @pass_argv
|
||||
|
@ -85,9 +83,7 @@ class Pry
|
|||
Pry.final_session_setup
|
||||
|
||||
# Option processors are optional.
|
||||
if option_processors
|
||||
option_processors.each { |processor| processor.call(opts) }
|
||||
end
|
||||
option_processors.each { |processor| processor.call(opts) } if option_processors
|
||||
|
||||
opts
|
||||
end
|
||||
|
@ -129,9 +125,7 @@ Pry::Slop.new do
|
|||
end
|
||||
end.parse(ARGV.dup)
|
||||
|
||||
if Pry.config.should_load_plugins
|
||||
Pry::CLI.add_plugin_options
|
||||
end
|
||||
Pry::CLI.add_plugin_options if Pry.config.should_load_plugins
|
||||
|
||||
# The default Pry command line options (before plugin options are included)
|
||||
Pry::CLI.add_options do
|
||||
|
|
|
@ -85,9 +85,7 @@ class Pry
|
|||
# @param [Integer?] start_line
|
||||
# @param [Symbol?] code_type
|
||||
def initialize(lines = [], start_line = 1, code_type = :ruby)
|
||||
if lines.is_a? String
|
||||
lines = lines.lines
|
||||
end
|
||||
lines = lines.lines if lines.is_a? String
|
||||
@lines = lines.each_with_index.map do |line, lineno|
|
||||
LOC.new(line, lineno + start_line.to_i)
|
||||
end
|
||||
|
@ -103,9 +101,7 @@ class Pry
|
|||
# @param [Integer?] lineno
|
||||
# @return [String] The inserted line.
|
||||
def push(line, lineno = nil)
|
||||
if lineno.nil?
|
||||
lineno = @lines.last.lineno + 1
|
||||
end
|
||||
lineno = @lines.last.lineno + 1 if lineno.nil?
|
||||
@lines.push(LOC.new(line, lineno))
|
||||
line
|
||||
end
|
||||
|
|
|
@ -429,9 +429,7 @@ WARN
|
|||
return void
|
||||
end
|
||||
|
||||
if command_options[:argument_required] && args.empty?
|
||||
raise CommandError, "The command '#{command_name}' requires an argument."
|
||||
end
|
||||
raise CommandError, "The command '#{command_name}' requires an argument." if command_options[:argument_required] && args.empty?
|
||||
|
||||
ret = use_unpatched_symbol do
|
||||
call_with_hooks(*args)
|
||||
|
|
|
@ -310,12 +310,8 @@ class Pry
|
|||
# Pry.config.commands["help"] = MyHelpCommand
|
||||
#
|
||||
def []=(pattern, command)
|
||||
if command.equal?(nil)
|
||||
return @commands.delete(pattern)
|
||||
end
|
||||
unless Class === command && command < Pry::Command
|
||||
raise TypeError, "command is not a subclass of Pry::Command"
|
||||
end
|
||||
return @commands.delete(pattern) if command.equal?(nil)
|
||||
raise TypeError, "command is not a subclass of Pry::Command" unless Class === command && command < Pry::Command
|
||||
|
||||
bind_command_to_pattern = pattern != command.match
|
||||
if bind_command_to_pattern
|
||||
|
|
|
@ -24,9 +24,7 @@ class Pry
|
|||
state.old_stack ||= []
|
||||
|
||||
if arg_string.strip == "-"
|
||||
unless state.old_stack.empty?
|
||||
_pry_.binding_stack, state.old_stack = state.old_stack, _pry_.binding_stack
|
||||
end
|
||||
_pry_.binding_stack, state.old_stack = state.old_stack, _pry_.binding_stack unless state.old_stack.empty?
|
||||
else
|
||||
stack = ObjectPath.new(arg_string, _pry_.binding_stack).resolve
|
||||
|
||||
|
|
|
@ -39,9 +39,7 @@ class Pry
|
|||
end
|
||||
|
||||
def process
|
||||
if bad_option_combination?
|
||||
raise CommandError, "Only one of --ex, --temp, --in, --method and FILE may be specified."
|
||||
end
|
||||
raise CommandError, "Only one of --ex, --temp, --in, --method and FILE may be specified." if bad_option_combination?
|
||||
|
||||
if repl_edit?
|
||||
# code defined in pry, eval'd within pry.
|
||||
|
|
|
@ -32,9 +32,7 @@ class Pry
|
|||
|
||||
cc = CodeCollector.new(args, opts, _pry_)
|
||||
|
||||
if cc.content =~ /\A\s*\z/
|
||||
raise CommandError, "Found no code to gist."
|
||||
end
|
||||
raise CommandError, "Found no code to gist." if cc.content =~ /\A\s*\z/
|
||||
|
||||
if opts.present?(:clip)
|
||||
clipboard_content(cc.content)
|
||||
|
@ -59,9 +57,7 @@ class Pry
|
|||
corrected_index = index + range.first
|
||||
if code && code != ""
|
||||
content << code
|
||||
if code !~ /;\Z/
|
||||
content << "#{comment_expression_result_for_gist(_pry_.config.gist.inspecter.call(_pry_.output_ring[corrected_index]))}"
|
||||
end
|
||||
content << "#{comment_expression_result_for_gist(_pry_.config.gist.inspecter.call(_pry_.output_ring[corrected_index]))}" if code !~ /;\Z/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,9 +45,7 @@ class Pry
|
|||
sorted_group_names(groups).each do |group_name|
|
||||
commands = sorted_commands(groups[group_name])
|
||||
|
||||
if commands.any?
|
||||
help_text << help_text_for_commands(group_name, commands)
|
||||
end
|
||||
help_text << help_text_for_commands(group_name, commands) if commands.any?
|
||||
end
|
||||
|
||||
_pry_.pager.page help_text.join("\n\n")
|
||||
|
|
|
@ -36,13 +36,9 @@ class Pry
|
|||
def process
|
||||
@history = find_history
|
||||
|
||||
if opts.present?(:show)
|
||||
@history = @history.between(opts[:show])
|
||||
end
|
||||
@history = @history.between(opts[:show]) if opts.present?(:show)
|
||||
|
||||
if opts.present?(:grep)
|
||||
@history = @history.grep(opts[:grep])
|
||||
end
|
||||
@history = @history.grep(opts[:grep]) if opts.present?(:grep)
|
||||
|
||||
@history =
|
||||
if opts.present?(:head)
|
||||
|
@ -75,9 +71,7 @@ class Pry
|
|||
private
|
||||
|
||||
def process_display
|
||||
unless opts.present?(:'no-numbers')
|
||||
@history = @history.with_line_numbers
|
||||
end
|
||||
@history = @history.with_line_numbers unless opts.present?(:'no-numbers')
|
||||
|
||||
_pry_.pager.open do |pager|
|
||||
@history.print_to_output(pager, true)
|
||||
|
@ -89,9 +83,7 @@ class Pry
|
|||
when Range
|
||||
@history = @history.between(opts[:save])
|
||||
|
||||
unless args.first
|
||||
raise CommandError, "Must provide a file name."
|
||||
end
|
||||
raise CommandError, "Must provide a file name." unless args.first
|
||||
|
||||
file_name = File.expand_path(args.first)
|
||||
when String
|
||||
|
|
|
@ -60,12 +60,8 @@ class Pry
|
|||
"#{' ' * 32}Constants that are pending autoload? are also shown (in yellow)"
|
||||
opt.on :i, :ivars, "Show instance variables (in blue) and class variables (in bright blue)"
|
||||
opt.on :G, :grep, "Filter output by regular expression", argument: true
|
||||
if Object.respond_to?(:deprecate_constant)
|
||||
opt.on :d, :dconstants, "Show deprecated constants"
|
||||
end
|
||||
if Helpers::Platform.jruby?
|
||||
opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)"
|
||||
end
|
||||
opt.on :d, :dconstants, "Show deprecated constants" if Object.respond_to?(:deprecate_constant)
|
||||
opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)" if Helpers::Platform.jruby?
|
||||
end
|
||||
|
||||
# Exclude -q, -v and --grep because they,
|
||||
|
|
|
@ -16,9 +16,7 @@ class Pry
|
|||
Pry::Method.all_from_obj(@interrogatee)
|
||||
end
|
||||
|
||||
if Pry::Helpers::Platform.jruby? && !@jruby_switch
|
||||
methods = trim_jruby_aliases(methods)
|
||||
end
|
||||
methods = trim_jruby_aliases(methods) if Pry::Helpers::Platform.jruby? && !@jruby_switch
|
||||
|
||||
methods.select { |method| @ppp_switch || method.visibility == :public }
|
||||
end
|
||||
|
|
|
@ -49,9 +49,7 @@ class Pry
|
|||
end
|
||||
|
||||
def show_input
|
||||
if opts.present?(:print) || !Pry::Code.complete_expression?(eval_string)
|
||||
run "show-input"
|
||||
end
|
||||
run "show-input" if opts.present?(:print) || !Pry::Code.complete_expression?(eval_string)
|
||||
end
|
||||
|
||||
def content_after_options
|
||||
|
|
|
@ -38,9 +38,7 @@ class Pry
|
|||
end
|
||||
|
||||
def reload_current_file
|
||||
if !File.exist?(current_file)
|
||||
raise CommandError, "Current file: #{current_file} cannot be found on disk!"
|
||||
end
|
||||
raise CommandError, "Current file: #{current_file} cannot be found on disk!" if !File.exist?(current_file)
|
||||
|
||||
load current_file
|
||||
output.puts "The current file: #{current_file} was reloaded!"
|
||||
|
|
|
@ -15,9 +15,7 @@ class Pry
|
|||
BANNER
|
||||
|
||||
def process(spec)
|
||||
unless spec
|
||||
return output.puts "Please provide a class, module, or method name (e.g: ri Array#push)"
|
||||
end
|
||||
return output.puts "Please provide a class, module, or method name (e.g: ri Array#push)" unless spec
|
||||
|
||||
# Lazily load RI
|
||||
require 'rdoc/ri/driver'
|
||||
|
|
|
@ -57,9 +57,7 @@ class Pry
|
|||
return if !(dest && cd_path_exists?) || special_case_path?(dest)
|
||||
|
||||
cd_path_env.split(File::PATH_SEPARATOR).each do |path|
|
||||
if File.directory?(path) && path.split(File::SEPARATOR).last == dest
|
||||
return path
|
||||
end
|
||||
return path if File.directory?(path) && path.split(File::SEPARATOR).last == dest
|
||||
end
|
||||
|
||||
return nil
|
||||
|
|
|
@ -109,9 +109,7 @@ class Pry
|
|||
h << "\n#{bold('Number of lines:')} " << "#{content.lines.count}\n\n"
|
||||
h << bold('** Warning:') << " Cannot find code for #{@original_code_object.nonblank_name}. Showing superclass #{code_object.nonblank_name} instead. **\n\n" if @used_super
|
||||
|
||||
if content.lines.none?
|
||||
h << bold('** Warning:') << " Cannot find code for '#{code_object.name}' (source_location is nil)"
|
||||
end
|
||||
h << bold('** Warning:') << " Cannot find code for '#{code_object.name}' (source_location is nil)" if content.lines.none?
|
||||
|
||||
h
|
||||
end
|
||||
|
|
|
@ -80,9 +80,7 @@ class Pry
|
|||
def eval_and_print_changed(output)
|
||||
expressions.each do |expr|
|
||||
expr.eval!
|
||||
if expr.changed?
|
||||
output.puts "#{blue "watch"}: #{expr}"
|
||||
end
|
||||
output.puts "#{blue "watch"}: #{expr}" if expr.changed?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -86,9 +86,7 @@ class Pry
|
|||
end
|
||||
|
||||
def process
|
||||
if bad_option_combination?
|
||||
raise CommandError, "Only one of -m, -c, -f, and LINES may be specified."
|
||||
end
|
||||
raise CommandError, "Only one of -m, -c, -f, and LINES may be specified." if bad_option_combination?
|
||||
|
||||
if nothing_to_do?
|
||||
return
|
||||
|
@ -152,9 +150,7 @@ class Pry
|
|||
def method_code
|
||||
return @method_code if @method_code
|
||||
|
||||
if valid_method?
|
||||
@method_code = Pry::Code.from_method(@method)
|
||||
end
|
||||
@method_code = Pry::Code.from_method(@method) if valid_method?
|
||||
end
|
||||
|
||||
# This either returns the `target_self`
|
||||
|
|
|
@ -164,9 +164,7 @@ class Pry
|
|||
#
|
||||
def []=(key, value)
|
||||
key = key.to_s
|
||||
if @reserved_keys.include?(key)
|
||||
raise ReservedKeyError, "It is not possible to use '#{key}' as a key name, please choose a different key name."
|
||||
end
|
||||
raise ReservedKeyError, "It is not possible to use '#{key}' as a key name, please choose a different key name." if @reserved_keys.include?(key)
|
||||
|
||||
__push(key, value)
|
||||
end
|
||||
|
|
|
@ -23,9 +23,7 @@ class Pry
|
|||
def get_method_or_raise(name, target, opts = {}, omit_help = false)
|
||||
meth = Pry::Method.from_str(name, target, opts)
|
||||
|
||||
if name && !meth
|
||||
command_error("The method '#{name}' could not be found.", omit_help, MethodNotFound)
|
||||
end
|
||||
command_error("The method '#{name}' could not be found.", omit_help, MethodNotFound) if name && !meth
|
||||
|
||||
(opts[:super] || 0).times do
|
||||
if meth.super
|
||||
|
@ -35,9 +33,7 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
if !meth || (!name && internal_binding?(target))
|
||||
command_error("No method name given, and context is not a method.", omit_help, MethodNotFound)
|
||||
end
|
||||
command_error("No method name given, and context is not a method.", omit_help, MethodNotFound) if !meth || (!name && internal_binding?(target))
|
||||
|
||||
set_file_and_dir_locals(meth.source_file)
|
||||
meth
|
||||
|
|
|
@ -41,9 +41,7 @@ class Pry
|
|||
return line if line == last_line
|
||||
|
||||
@history << line
|
||||
if !should_ignore?(line) && Pry.config.history.should_save
|
||||
@saver.call(line)
|
||||
end
|
||||
@saver.call(line) if !should_ignore?(line) && Pry.config.history.should_save
|
||||
|
||||
line
|
||||
end
|
||||
|
@ -97,9 +95,7 @@ class Pry
|
|||
def read_from_file
|
||||
path = history_file_path
|
||||
|
||||
if File.exist?(path)
|
||||
File.foreach(path) { |line| yield(line) }
|
||||
end
|
||||
File.foreach(path) { |line| yield(line) } if File.exist?(path)
|
||||
rescue SystemCallError => error
|
||||
warn "Unable to read history file: #{error.message}"
|
||||
end
|
||||
|
@ -114,9 +110,7 @@ class Pry
|
|||
if defined?(@history_file)
|
||||
@history_file
|
||||
else
|
||||
unless File.exist?(history_file_path)
|
||||
FileUtils.mkdir_p(File.dirname(history_file_path))
|
||||
end
|
||||
FileUtils.mkdir_p(File.dirname(history_file_path)) unless File.exist?(history_file_path)
|
||||
@history_file = File.open(history_file_path, 'a', 0600).tap do |file|
|
||||
file.sync = true
|
||||
end
|
||||
|
|
|
@ -70,13 +70,9 @@ class Pry
|
|||
|
||||
# do not allow duplicates, but allow multiple `nil` hooks
|
||||
# (anonymous hooks)
|
||||
if hook_exists?(event_name, hook_name) && !hook_name.nil?
|
||||
raise ArgumentError, "Hook with name '#{hook_name}' already defined!"
|
||||
end
|
||||
raise ArgumentError, "Hook with name '#{hook_name}' already defined!" if hook_exists?(event_name, hook_name) && !hook_name.nil?
|
||||
|
||||
if !block && !callable
|
||||
raise ArgumentError, "Must provide a block or callable."
|
||||
end
|
||||
raise ArgumentError, "Must provide a block or callable." if !block && !callable
|
||||
|
||||
# ensure we only have one anonymous hook
|
||||
@hooks[event_name].delete_if { |h, _k| h.nil? } if hook_name.nil?
|
||||
|
|
|
@ -353,9 +353,7 @@ class Pry
|
|||
# @param [String] token a token from Coderay
|
||||
# @param [Symbol] kind the kind of that token
|
||||
def track_module_nesting_end(token, kind = :keyword)
|
||||
if kind == :keyword && (token == "class" || token == "module")
|
||||
@module_nesting.pop
|
||||
end
|
||||
@module_nesting.pop if kind == :keyword && (token == "class" || token == "module")
|
||||
end
|
||||
|
||||
# Return a list of strings which can be used to re-construct the Module.nesting at
|
||||
|
|
|
@ -176,9 +176,7 @@ class Pry
|
|||
|
||||
# jruby doesn't always provide #instance_methods() on each
|
||||
# object.
|
||||
if m.respond_to?(:instance_methods)
|
||||
candidates.merge m.instance_methods(false).collect(&:to_s)
|
||||
end
|
||||
candidates.merge m.instance_methods(false).collect(&:to_s) if m.respond_to?(:instance_methods)
|
||||
end
|
||||
end
|
||||
select_message(path, receiver, message, candidates.sort)
|
||||
|
@ -195,9 +193,7 @@ class Pry
|
|||
bind
|
||||
).collect(&:to_s)
|
||||
|
||||
if eval("respond_to?(:class_variables)", bind)
|
||||
candidates += eval("class_variables", bind).collect(&:to_s)
|
||||
end
|
||||
candidates += eval("class_variables", bind).collect(&:to_s) if eval("respond_to?(:class_variables)", bind)
|
||||
candidates = (candidates | ReservedWords | custom_completions).grep(/^#{Regexp.quote(input)}/)
|
||||
candidates.collect(&path)
|
||||
end
|
||||
|
|
|
@ -478,9 +478,7 @@ class Pry
|
|||
Pry::MethodInfo.info_for(@method) || raise(CommandError, "Cannot locate this method: #{name}. (source_location returns nil)")
|
||||
else
|
||||
fail_msg = "Cannot locate this method: #{name}."
|
||||
if Helpers::Platform.mri?
|
||||
fail_msg += " Invoke the 'gem-install pry-doc' Pry command to get access to Ruby Core documentation.\n"
|
||||
end
|
||||
fail_msg += " Invoke the 'gem-install pry-doc' Pry command to get access to Ruby Core documentation.\n" if Helpers::Platform.mri?
|
||||
raise CommandError, fail_msg
|
||||
end
|
||||
end
|
||||
|
@ -508,9 +506,7 @@ class Pry
|
|||
tokens = CodeRay.scan(first_ln, :ruby)
|
||||
tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens)
|
||||
tokens.each_cons(2) do |t1, t2|
|
||||
if t2.last == :method || t2.last == :ident && t1 == [".", :operator]
|
||||
return t2.first
|
||||
end
|
||||
return t2.first if t2.last == :method || t2.last == :ident && t1 == [".", :operator]
|
||||
end
|
||||
|
||||
nil
|
||||
|
@ -518,9 +514,7 @@ class Pry
|
|||
|
||||
def c_source
|
||||
info = pry_doc_info
|
||||
if info && info.source
|
||||
strip_comments_from_c_code(info.source)
|
||||
end
|
||||
strip_comments_from_c_code(info.source) if info && info.source
|
||||
end
|
||||
|
||||
def ruby_source
|
||||
|
|
|
@ -124,9 +124,7 @@ class Pry
|
|||
# superclass method.
|
||||
def find_method_in_superclass
|
||||
guess = method
|
||||
if skip_superclass_search?
|
||||
return guess
|
||||
end
|
||||
return guess if skip_superclass_search?
|
||||
|
||||
while guess
|
||||
# needs rescue if this is a Disowned method or a C method or something...
|
||||
|
|
|
@ -130,9 +130,7 @@ class Pry
|
|||
|
||||
# Default to less, and make sure less is being passed the correct
|
||||
# options
|
||||
if pager.strip.empty? || pager =~ /^less\b/
|
||||
pager = "less -R -F -X"
|
||||
end
|
||||
pager = "less -R -F -X" if pager.strip.empty? || pager =~ /^less\b/
|
||||
|
||||
pager
|
||||
end
|
||||
|
@ -172,9 +170,7 @@ class Pry
|
|||
@tracker.record str
|
||||
@buffer << str
|
||||
|
||||
if @tracker.page?
|
||||
write_to_pager @buffer
|
||||
end
|
||||
write_to_pager @buffer if @tracker.page?
|
||||
end
|
||||
rescue Errno::EPIPE
|
||||
raise StopPaging
|
||||
|
|
|
@ -68,9 +68,7 @@ class Pry
|
|||
def supported?
|
||||
pry_version = Gem::Version.new(VERSION)
|
||||
spec.dependencies.each do |dependency|
|
||||
if dependency.name == "pry"
|
||||
return dependency.requirement.satisfied_by?(pry_version)
|
||||
end
|
||||
return dependency.requirement.satisfied_by?(pry_version) if dependency.name == "pry"
|
||||
end
|
||||
true
|
||||
end
|
||||
|
|
|
@ -84,13 +84,9 @@ class Pry
|
|||
def add(name, description = '', separators = %w[> *])
|
||||
name = name.to_s
|
||||
|
||||
unless separators.size == 2
|
||||
raise ArgumentError, "separators size must be 2, given #{separators.size}"
|
||||
end
|
||||
raise ArgumentError, "separators size must be 2, given #{separators.size}" unless separators.size == 2
|
||||
|
||||
if @prompts.key?(name)
|
||||
raise ArgumentError, "the '#{name}' prompt was already added"
|
||||
end
|
||||
raise ArgumentError, "the '#{name}' prompt was already added" if @prompts.key?(name)
|
||||
|
||||
@prompts[name] = new(
|
||||
name,
|
||||
|
|
|
@ -173,9 +173,7 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
|
|||
# Pry.start(Object.new, :input => MyInput.new)
|
||||
def self.start(target = nil, options = {})
|
||||
return if ENV['DISABLE_PRY']
|
||||
if ENV['FAIL_PRY']
|
||||
raise 'You have FAIL_PRY set to true, which results in Pry calls failing'
|
||||
end
|
||||
raise 'You have FAIL_PRY set to true, which results in Pry calls failing' if ENV['FAIL_PRY']
|
||||
|
||||
options = options.to_hash
|
||||
|
||||
|
@ -194,9 +192,7 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
|
|||
options[:backtrace] = caller
|
||||
|
||||
# If Pry was started via `binding.pry`, elide that from the backtrace
|
||||
if options[:backtrace].first =~ /pry.*core_extensions.*pry/
|
||||
options[:backtrace].shift
|
||||
end
|
||||
options[:backtrace].shift if options[:backtrace].first =~ /pry.*core_extensions.*pry/
|
||||
end
|
||||
|
||||
driver = options[:driver] || Pry::REPL
|
||||
|
|
|
@ -300,9 +300,7 @@ class Pry
|
|||
end
|
||||
|
||||
if complete_expr
|
||||
if @eval_string =~ /;\Z/ || @eval_string.empty? || @eval_string =~ /\A *#.*\n\z/
|
||||
@suppress_output = true
|
||||
end
|
||||
@suppress_output = true if @eval_string =~ /;\Z/ || @eval_string.empty? || @eval_string =~ /\A *#.*\n\z/
|
||||
|
||||
# A bug in jruby makes java.lang.Exception not rescued by
|
||||
# `rescue Pry::RescuableException` clause.
|
||||
|
@ -316,9 +314,7 @@ class Pry
|
|||
# This workaround has a side effect: java exceptions specified
|
||||
# in `Pry.config.unrescued_exceptions` are ignored.
|
||||
jruby_exceptions = []
|
||||
if Helpers::Platform.jruby?
|
||||
jruby_exceptions << Java::JavaLang::Exception
|
||||
end
|
||||
jruby_exceptions << Java::JavaLang::Exception if Helpers::Platform.jruby?
|
||||
|
||||
begin
|
||||
# Reset eval string, in case we're evaluating Ruby that does something
|
||||
|
@ -331,9 +327,7 @@ class Pry
|
|||
# Eliminate following warning:
|
||||
# warning: singleton on non-persistent Java type X
|
||||
# (http://wiki.jruby.org/Persistence)
|
||||
if Helpers::Platform.jruby? && e.class.respond_to?('__persistent__')
|
||||
e.class.__persistent__ = true
|
||||
end
|
||||
e.class.__persistent__ = true if Helpers::Platform.jruby? && e.class.respond_to?('__persistent__')
|
||||
self.last_exception = e
|
||||
result = e
|
||||
end
|
||||
|
|
|
@ -23,9 +23,7 @@ class Pry
|
|||
|
||||
@readline_output = nil
|
||||
|
||||
if options[:target]
|
||||
@pry.push_binding options[:target]
|
||||
end
|
||||
@pry.push_binding options[:target] if options[:target]
|
||||
end
|
||||
|
||||
# Start the read-eval-print loop.
|
||||
|
@ -151,9 +149,7 @@ class Pry
|
|||
puts "Error: #{e.message}"
|
||||
output.puts e.backtrace
|
||||
exception_count += 1
|
||||
if exception_count < 5
|
||||
retry
|
||||
end
|
||||
retry if exception_count < 5
|
||||
puts "FATAL: Pry failed to get user input using `#{input}`."
|
||||
puts "To fix this you may be able to pass input and output file " \
|
||||
"descriptors to pry directly. e.g."
|
||||
|
@ -227,9 +223,7 @@ class Pry
|
|||
def set_readline_output
|
||||
return if @readline_output
|
||||
|
||||
if piping?
|
||||
@readline_output = (Readline.output = Pry.config.output)
|
||||
end
|
||||
@readline_output = (Readline.output = Pry.config.output) if piping?
|
||||
end
|
||||
|
||||
# Calculates correct overhang for current line. Supports vi Readline
|
||||
|
@ -246,9 +240,7 @@ class Pry
|
|||
begin
|
||||
# rb-readline doesn't support this method:
|
||||
# https://github.com/ConnorAtherton/rb-readline/issues/152
|
||||
if Readline.vi_editing_mode?
|
||||
overhang += current_prompt.length - indented_val.length
|
||||
end
|
||||
overhang += current_prompt.length - indented_val.length if Readline.vi_editing_mode?
|
||||
rescue NotImplementedError
|
||||
# VI editing mode is unsupported on JRuby.
|
||||
# https://github.com/pry/pry/issues/1840
|
||||
|
|
|
@ -233,13 +233,9 @@ class Pry
|
|||
"Missing required option(s): #{missing_options.map(&:key).join(', ')}"
|
||||
end
|
||||
|
||||
if @unknown_options.any?
|
||||
raise InvalidOptionError, "Unknown options #{@unknown_options.join(', ')}"
|
||||
end
|
||||
raise InvalidOptionError, "Unknown options #{@unknown_options.join(', ')}" if @unknown_options.any?
|
||||
|
||||
if @triggered_options.empty? && @callbacks[:no_options]
|
||||
@callbacks[:no_options].each { |cb| cb.call(self) }
|
||||
end
|
||||
@callbacks[:no_options].each { |cb| cb.call(self) } if @triggered_options.empty? && @callbacks[:no_options]
|
||||
|
||||
@runner.call(self, items) if @runner.respond_to?(:call)
|
||||
|
||||
|
@ -280,9 +276,7 @@ class Pry
|
|||
# include_commands - If true, merge options from all sub-commands.
|
||||
def to_hash(include_commands = false)
|
||||
hash = Hash[options.map { |opt| [opt.key.to_sym, opt.value] }]
|
||||
if include_commands
|
||||
@commands.each { |cmd, opts| hash.merge!(cmd.to_sym => opts.to_hash) }
|
||||
end
|
||||
@commands.each { |cmd, opts| hash.merge!(cmd.to_sym => opts.to_hash) } if include_commands
|
||||
hash
|
||||
end
|
||||
alias to_h to_hash
|
||||
|
@ -310,9 +304,7 @@ class Pry
|
|||
# end
|
||||
def run(callable = nil, &block)
|
||||
@runner = callable || block
|
||||
unless @runner.respond_to?(:call)
|
||||
raise ArgumentError, "You must specify a callable object or a block to #run"
|
||||
end
|
||||
raise ArgumentError, "You must specify a callable object or a block to #run" unless @runner.respond_to?(:call)
|
||||
end
|
||||
|
||||
# Check for an options presence.
|
||||
|
@ -476,9 +468,7 @@ class Pry
|
|||
if option.expects_argument?
|
||||
argument ||= items.at(index + 1)
|
||||
|
||||
if !argument || argument =~ /\A--?[a-zA-Z][a-zA-Z0-9_-]*\z/
|
||||
raise MissingArgumentError, "#{option.key} expects an argument"
|
||||
end
|
||||
raise MissingArgumentError, "#{option.key} expects an argument" if !argument || argument =~ /\A--?[a-zA-Z][a-zA-Z0-9_-]*\z/
|
||||
|
||||
execute_option(option, argument, index, item)
|
||||
elsif option.accepts_optional_argument?
|
||||
|
@ -511,9 +501,7 @@ class Pry
|
|||
# Returns nothing.
|
||||
def execute_option(option, argument, index, item = nil)
|
||||
if !option
|
||||
if config[:multiple_switches] && strict?
|
||||
raise InvalidOptionError, "Unknown option -#{item}"
|
||||
end
|
||||
raise InvalidOptionError, "Unknown option -#{item}" if config[:multiple_switches] && strict?
|
||||
|
||||
return
|
||||
end
|
||||
|
@ -527,9 +515,7 @@ class Pry
|
|||
option.value = option.count > 0
|
||||
end
|
||||
|
||||
if option.match? && !argument.match(option.config[:match])
|
||||
raise InvalidArgumentError, "#{argument} is an invalid argument"
|
||||
end
|
||||
raise InvalidArgumentError, "#{argument} is an invalid argument" if option.match? && !argument.match(option.config[:match])
|
||||
|
||||
option.call(option.value)
|
||||
end
|
||||
|
|
|
@ -143,9 +143,7 @@ class Pry
|
|||
if (opts = commands['default'])
|
||||
opts.parse! items
|
||||
else
|
||||
if config[:strict] && items[0]
|
||||
raise InvalidCommandError, "Unknown command `#{items[0]}`"
|
||||
end
|
||||
raise InvalidCommandError, "Unknown command `#{items[0]}`" if config[:strict] && items[0]
|
||||
end
|
||||
execute_global_opts! items
|
||||
end
|
||||
|
@ -162,12 +160,8 @@ class Pry
|
|||
defaults = commands.delete('default')
|
||||
globals = commands.delete('global')
|
||||
helps = commands.reject { |_, v| v.options.none? }
|
||||
if globals && globals.options.any?
|
||||
helps['Global options'] = globals.to_s
|
||||
end
|
||||
if defaults && defaults.options.any?
|
||||
helps['Other options'] = defaults.to_s
|
||||
end
|
||||
helps['Global options'] = globals.to_s if globals && globals.options.any?
|
||||
helps['Other options'] = defaults.to_s if defaults && defaults.options.any?
|
||||
banner = @banner ? "#{@banner}\n" : ""
|
||||
banner + helps.map { |key, opts| " #{key}\n#{opts}" }.join("\n\n")
|
||||
end
|
||||
|
|
|
@ -49,15 +49,11 @@ class Pry
|
|||
count: proc { @count }
|
||||
}
|
||||
|
||||
if long && long.size > @slop.config[:longest_flag]
|
||||
@slop.config[:longest_flag] = long.size
|
||||
end
|
||||
@slop.config[:longest_flag] = long.size if long && long.size > @slop.config[:longest_flag]
|
||||
|
||||
@config.each_key do |key|
|
||||
predicate = :"#{key}?"
|
||||
unless self.class.method_defined? predicate
|
||||
self.class.__send__(:define_method, predicate) { !!@config[key] }
|
||||
end
|
||||
self.class.__send__(:define_method, predicate) { !!@config[key] } unless self.class.method_defined? predicate
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -92,9 +88,7 @@ class Pry
|
|||
if config[:as].to_s.casecmp('array') == 0
|
||||
@value ||= []
|
||||
|
||||
if new_value.respond_to?(:split)
|
||||
@value.concat new_value.split(config[:delimiter], config[:limit])
|
||||
end
|
||||
@value.concat new_value.split(config[:delimiter], config[:limit]) if new_value.respond_to?(:split)
|
||||
else
|
||||
@value = new_value
|
||||
end
|
||||
|
@ -106,9 +100,7 @@ class Pry
|
|||
def value
|
||||
value = @value.nil? ? config[:default] : @value
|
||||
|
||||
if [true, false, nil].include?(value) && config[:as].to_s != 'count'
|
||||
return value
|
||||
end
|
||||
return value if [true, false, nil].include?(value) && config[:as].to_s != 'count'
|
||||
|
||||
type = config[:as]
|
||||
if type.respond_to?(:call)
|
||||
|
|
|
@ -6,9 +6,7 @@ class Pry
|
|||
# If the window size cannot be determined, return nil.
|
||||
def screen_size
|
||||
rows, cols = actual_screen_size
|
||||
if rows.to_i != 0 && cols.to_i != 0
|
||||
[rows.to_i, cols.to_i]
|
||||
end
|
||||
[rows.to_i, cols.to_i] if rows.to_i != 0 && cols.to_i != 0
|
||||
end
|
||||
|
||||
# Return a screen size or a default if that fails.
|
||||
|
@ -45,9 +43,7 @@ class Pry
|
|||
require 'io/console'
|
||||
|
||||
begin
|
||||
if $stdout.respond_to?(:tty?) && $stdout.tty? && $stdout.respond_to?(:winsize)
|
||||
$stdout.winsize
|
||||
end
|
||||
$stdout.winsize if $stdout.respond_to?(:tty?) && $stdout.tty? && $stdout.respond_to?(:winsize)
|
||||
rescue Errno::EOPNOTSUPP
|
||||
# $stdout is probably a socket, which doesn't support #winsize.
|
||||
end
|
||||
|
|
|
@ -2,9 +2,7 @@ class Pry
|
|||
module Testable
|
||||
module Evalable
|
||||
def pry_tester(*args, &block)
|
||||
if args.length == 0 || args[0].is_a?(Hash)
|
||||
args.unshift(Pry.toplevel_binding)
|
||||
end
|
||||
args.unshift(Pry.toplevel_binding) if args.length == 0 || args[0].is_a?(Hash)
|
||||
Pry::Testable::PryTester.new(*args).tap do |t|
|
||||
t.singleton_class.class_eval(&block) if block
|
||||
end
|
||||
|
|
|
@ -18,9 +18,7 @@ class Pry
|
|||
|
||||
strs.flatten.each do |str|
|
||||
# Check for space prefix. See #1369.
|
||||
if str !~ /^\s\S/
|
||||
str = "#{str.strip}\n"
|
||||
end
|
||||
str = "#{str.strip}\n" if str !~ /^\s\S/
|
||||
@history.push str if @history
|
||||
|
||||
result =
|
||||
|
|
|
@ -27,9 +27,7 @@ class Pry
|
|||
# @example
|
||||
# Pry::WrappedModule.from_str("Pry::Code")
|
||||
def self.from_str(mod_name, target = TOPLEVEL_BINDING)
|
||||
if safe_to_evaluate?(mod_name, target)
|
||||
Pry::WrappedModule.new(target.eval(mod_name))
|
||||
end
|
||||
Pry::WrappedModule.new(target.eval(mod_name)) if safe_to_evaluate?(mod_name, target)
|
||||
rescue RescuableException
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -13,9 +13,7 @@ describe "show-doc" do
|
|||
end
|
||||
|
||||
after do
|
||||
if Symbol.method_defined? :call
|
||||
Symbol.class_eval { undef :call }
|
||||
end
|
||||
Symbol.class_eval { undef :call } if Symbol.method_defined? :call
|
||||
end
|
||||
|
||||
it "emits a deprecation warning" do
|
||||
|
|
|
@ -12,9 +12,7 @@ describe "wtf?!" do
|
|||
end
|
||||
|
||||
it "unwinds nested exceptions" do
|
||||
if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.0.0')
|
||||
skip('Exception#cause is not supported')
|
||||
end
|
||||
skip('Exception#cause is not supported') if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.0.0')
|
||||
|
||||
begin
|
||||
begin
|
||||
|
|
|
@ -36,9 +36,7 @@ class ReplTester
|
|||
instance.ensure_exit
|
||||
end
|
||||
ensure
|
||||
if instance && instance.thread && instance.thread.alive?
|
||||
instance.thread.kill
|
||||
end
|
||||
instance.thread.kill if instance && instance.thread && instance.thread.alive?
|
||||
end
|
||||
|
||||
attr_accessor :thread, :mailbox, :last_prompt
|
||||
|
|
Loading…
Add table
Reference in a new issue