Class: Pry::Command::Whereami

Inherits:
Pry::ClassCommand show all
Defined in:
lib/pry/commands/whereami.rb

Constant Summary

Constants inherited from Pry::Command

VOID_VALUE

Class Attribute Summary collapse

Attributes inherited from Pry::ClassCommand

#args, #opts

Attributes inherited from Pry::Command

#_pry_, #arg_string, #captures, #command_block, #command_set, #context, #eval_string, #output, #target

Instance Method Summary collapse

Methods inherited from Pry::ClassCommand

#call, #complete, doc, #help, inherited, #slop, source, source_file, source_line, source_location, #subcommands

Methods inherited from Pry::Command

banner, #block, #call_safely, #check_for_command_collision, #command_name, command_name, #command_options, command_regex, #commands, #complete, convert_to_regex, default_options, #dependencies_met?, #description, doc, group, hooks, #initialize, inspect, #interpolate_string, #match, match_score, matches?, #name, name, options, #process_line, #run, #source, source, source_file, source_line, #source_location, source_location, #state, subclass, #target_self, #text, #tokenize, #void

Methods included from Pry::CodeObject::Helpers

#c_method?, #command?, #module_with_yard_docs?, #real_method_object?

Methods included from Helpers::DocumentationHelpers

get_comment_content, process_comment_markup, process_rdoc, process_yardoc, process_yardoc_tag, strip_comments_from_c_code, strip_leading_whitespace

Methods included from Helpers::CommandHelpers

absolute_index_number, absolute_index_range, command_error, get_method_or_raise, internal_binding?, one_index_number, one_index_range, one_index_range_or_number, restrict_to_lines, set_file_and_dir_locals, temp_file, unindent

Methods included from Helpers::OptionsHelpers

method_object, method_options

Methods included from Helpers::BaseHelpers

colorize_code, command_dependencies_met?, find_command, heading, highlight, jruby?, jruby_19?, mri?, mri_19?, mri_20?, mri_21?, mri_2?, not_a_real_file?, rbx?, #safe_send, safe_send, silence_warnings, stagger_output, use_ansi_codes?, windows?, windows_ansi?

Constructor Details

This class inherits a constructor from Pry::Command

Class Attribute Details

.method_size_cutoffObject

Returns the value of attribute method_size_cutoff


5
6
7
# File 'lib/pry/commands/whereami.rb', line 5

def method_size_cutoff
  @method_size_cutoff
end

Instance Method Details

#bad_option_combination?Boolean

Returns:

  • (Boolean)

68
69
70
71
# 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

#codeObject


48
49
50
51
52
53
54
55
56
57
58
59
60
# 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

#code?Boolean

Returns:

  • (Boolean)

62
63
64
65
66
# File 'lib/pry/commands/whereami.rb', line 62

def code?
  !!code
rescue MethodSource::SourceNotFoundError
  false
end

#locationObject


73
74
75
# File 'lib/pry/commands/whereami.rb', line 73

def location
  "#{@file} @ line #{@line} #{@method && @method.name_with_owner}"
end

#options(opt) ⇒ Object


40
41
42
43
44
45
46
# 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

#processObject


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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).highlighted << "\n"

  _pry_.pager.page out
end

#setupObject


34
35
36
37
38
# 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