# File lib/pry/commands/whereami.rb, line 68 def bad_option_combination? [opts.present?(:m), opts.present?(:f), opts.present?(:c), args.any?].count(true) > 1 end
# File lib/pry/commands/whereami.rb, line 48 def code @code ||= if opts.present?(:m) method_code or raise CommandError, "Cannot find method code." elsif opts.present?(:c) class_code or raise CommandError, "Cannot find class code." elsif opts.present?(:f) Pry::Code.from_file(@file) elsif args.any? code_window else default_code end end
# File lib/pry/commands/whereami.rb, line 62 def code? !!code rescue MethodSource::SourceNotFoundError false end
# File lib/pry/commands/whereami.rb, line 73 def location "#{@file} @ line #{@line} #{@method && @method.name_with_owner}" end
# File lib/pry/commands/whereami.rb, line 40 def options(opt) opt.on :q, :quiet, "Don't display anything in case of an error" opt.on :n, :"no-line-numbers", "Do not display line numbers" opt.on :m, :"method", "Show the complete source for the current method." opt.on :c, :"class", "Show the complete source for the current class or module." opt.on :f, :"file", "Show the complete source for the current file." end
# File lib/pry/commands/whereami.rb, line 77 def process if bad_option_combination? raise CommandError, "Only one of -m, -c, -f, and LINES may be specified." end if nothing_to_do? return elsif internal_binding?(target) handle_internal_binding return end set_file_and_dir_locals(@file) out = "\n#{text.bold('From:')} #{location}:\n\n" + code.with_line_numbers(use_line_numbers?).with_marker(marker).to_s + "\n" stagger_output(out) end
# File lib/pry/commands/whereami.rb, line 34 def setup @file = expand_path(target.eval('__FILE__')) @line = target.eval('__LINE__') @method = Pry::Method.from_binding(target) end