pry 0.12.0-java → 0.14.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +162 -1
  3. data/LICENSE +1 -1
  4. data/README.md +331 -269
  5. data/bin/pry +5 -0
  6. data/lib/pry.rb +132 -119
  7. data/lib/pry/basic_object.rb +8 -4
  8. data/lib/pry/block_command.rb +22 -0
  9. data/lib/pry/class_command.rb +194 -0
  10. data/lib/pry/cli.rb +43 -51
  11. data/lib/pry/code.rb +40 -28
  12. data/lib/pry/code/code_file.rb +28 -24
  13. data/lib/pry/code/code_range.rb +4 -2
  14. data/lib/pry/code/loc.rb +15 -8
  15. data/lib/pry/code_object.rb +40 -38
  16. data/lib/pry/color_printer.rb +47 -46
  17. data/lib/pry/command.rb +166 -369
  18. data/lib/pry/command_set.rb +76 -73
  19. data/lib/pry/command_state.rb +31 -0
  20. data/lib/pry/commands/amend_line.rb +86 -81
  21. data/lib/pry/commands/bang.rb +18 -14
  22. data/lib/pry/commands/bang_pry.rb +15 -11
  23. data/lib/pry/commands/cat.rb +61 -54
  24. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  25. data/lib/pry/commands/cat/exception_formatter.rb +71 -60
  26. data/lib/pry/commands/cat/file_formatter.rb +55 -49
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  28. data/lib/pry/commands/cd.rb +40 -35
  29. data/lib/pry/commands/change_inspector.rb +29 -22
  30. data/lib/pry/commands/change_prompt.rb +44 -39
  31. data/lib/pry/commands/clear_screen.rb +16 -10
  32. data/lib/pry/commands/code_collector.rb +148 -133
  33. data/lib/pry/commands/disable_pry.rb +23 -19
  34. data/lib/pry/commands/easter_eggs.rb +19 -30
  35. data/lib/pry/commands/edit.rb +184 -161
  36. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  37. data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
  38. data/lib/pry/commands/exit.rb +39 -35
  39. data/lib/pry/commands/exit_all.rb +24 -20
  40. data/lib/pry/commands/exit_program.rb +20 -16
  41. data/lib/pry/commands/find_method.rb +168 -160
  42. data/lib/pry/commands/fix_indent.rb +16 -12
  43. data/lib/pry/commands/help.rb +140 -133
  44. data/lib/pry/commands/hist.rb +151 -150
  45. data/lib/pry/commands/import_set.rb +20 -16
  46. data/lib/pry/commands/jump_to.rb +25 -21
  47. data/lib/pry/commands/list_inspectors.rb +35 -28
  48. data/lib/pry/commands/ls.rb +124 -102
  49. data/lib/pry/commands/ls/constants.rb +59 -42
  50. data/lib/pry/commands/ls/formatter.rb +50 -46
  51. data/lib/pry/commands/ls/globals.rb +38 -34
  52. data/lib/pry/commands/ls/grep.rb +17 -13
  53. data/lib/pry/commands/ls/instance_vars.rb +29 -27
  54. data/lib/pry/commands/ls/interrogatable.rb +18 -12
  55. data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
  56. data/lib/pry/commands/ls/local_names.rb +26 -22
  57. data/lib/pry/commands/ls/local_vars.rb +38 -28
  58. data/lib/pry/commands/ls/ls_entity.rb +47 -51
  59. data/lib/pry/commands/ls/methods.rb +44 -43
  60. data/lib/pry/commands/ls/methods_helper.rb +46 -42
  61. data/lib/pry/commands/ls/self_methods.rb +23 -22
  62. data/lib/pry/commands/nesting.rb +21 -17
  63. data/lib/pry/commands/play.rb +93 -82
  64. data/lib/pry/commands/pry_backtrace.rb +22 -17
  65. data/lib/pry/commands/pry_version.rb +15 -11
  66. data/lib/pry/commands/raise_up.rb +27 -22
  67. data/lib/pry/commands/reload_code.rb +60 -48
  68. data/lib/pry/commands/reset.rb +16 -12
  69. data/lib/pry/commands/ri.rb +55 -45
  70. data/lib/pry/commands/save_file.rb +45 -43
  71. data/lib/pry/commands/shell_command.rb +51 -51
  72. data/lib/pry/commands/shell_mode.rb +21 -17
  73. data/lib/pry/commands/show_doc.rb +80 -68
  74. data/lib/pry/commands/show_info.rb +189 -171
  75. data/lib/pry/commands/show_input.rb +16 -11
  76. data/lib/pry/commands/show_source.rb +110 -45
  77. data/lib/pry/commands/stat.rb +35 -31
  78. data/lib/pry/commands/switch_to.rb +21 -15
  79. data/lib/pry/commands/toggle_color.rb +20 -16
  80. data/lib/pry/commands/watch_expression.rb +89 -86
  81. data/lib/pry/commands/watch_expression/expression.rb +32 -27
  82. data/lib/pry/commands/whereami.rb +156 -148
  83. data/lib/pry/commands/wtf.rb +75 -50
  84. data/lib/pry/config.rb +307 -25
  85. data/lib/pry/config/attributable.rb +22 -0
  86. data/lib/pry/config/lazy_value.rb +29 -0
  87. data/lib/pry/config/memoized_value.rb +34 -0
  88. data/lib/pry/config/value.rb +24 -0
  89. data/lib/pry/control_d_handler.rb +28 -0
  90. data/lib/pry/core_extensions.rb +9 -7
  91. data/lib/pry/editor.rb +48 -21
  92. data/lib/pry/env.rb +18 -0
  93. data/lib/pry/exception_handler.rb +43 -0
  94. data/lib/pry/exceptions.rb +13 -16
  95. data/lib/pry/forwardable.rb +5 -1
  96. data/lib/pry/helpers.rb +2 -0
  97. data/lib/pry/helpers/base_helpers.rb +68 -197
  98. data/lib/pry/helpers/command_helpers.rb +50 -61
  99. data/lib/pry/helpers/documentation_helpers.rb +20 -13
  100. data/lib/pry/helpers/options_helpers.rb +14 -7
  101. data/lib/pry/helpers/platform.rb +7 -5
  102. data/lib/pry/helpers/table.rb +33 -26
  103. data/lib/pry/helpers/text.rb +17 -14
  104. data/lib/pry/history.rb +48 -56
  105. data/lib/pry/hooks.rb +21 -12
  106. data/lib/pry/indent.rb +54 -50
  107. data/lib/pry/input_completer.rb +248 -230
  108. data/lib/pry/input_lock.rb +8 -9
  109. data/lib/pry/inspector.rb +36 -24
  110. data/lib/pry/last_exception.rb +45 -45
  111. data/lib/pry/method.rb +141 -94
  112. data/lib/pry/method/disowned.rb +16 -4
  113. data/lib/pry/method/patcher.rb +12 -3
  114. data/lib/pry/method/weird_method_locator.rb +68 -44
  115. data/lib/pry/object_path.rb +33 -25
  116. data/lib/pry/output.rb +121 -35
  117. data/lib/pry/pager.rb +186 -180
  118. data/lib/pry/prompt.rb +123 -54
  119. data/lib/pry/pry_class.rb +61 -103
  120. data/lib/pry/pry_instance.rb +217 -215
  121. data/lib/pry/repl.rb +18 -22
  122. data/lib/pry/repl_file_loader.rb +27 -21
  123. data/lib/pry/ring.rb +11 -6
  124. data/lib/pry/slop.rb +574 -563
  125. data/lib/pry/slop/commands.rb +164 -169
  126. data/lib/pry/slop/option.rb +172 -168
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable.rb +59 -61
  130. data/lib/pry/testable/evalable.rb +21 -12
  131. data/lib/pry/testable/mockable.rb +18 -10
  132. data/lib/pry/testable/pry_tester.rb +71 -56
  133. data/lib/pry/testable/utility.rb +29 -21
  134. data/lib/pry/testable/variables.rb +49 -43
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +27 -0
  137. data/lib/pry/wrapped_module.rb +51 -42
  138. data/lib/pry/wrapped_module/candidate.rb +21 -14
  139. metadata +37 -37
  140. data/lib/pry/commands.rb +0 -6
  141. data/lib/pry/commands/disabled_commands.rb +0 -2
  142. data/lib/pry/commands/gem_cd.rb +0 -26
  143. data/lib/pry/commands/gem_install.rb +0 -32
  144. data/lib/pry/commands/gem_list.rb +0 -33
  145. data/lib/pry/commands/gem_open.rb +0 -29
  146. data/lib/pry/commands/gem_readme.rb +0 -25
  147. data/lib/pry/commands/gem_search.rb +0 -40
  148. data/lib/pry/commands/gem_stats.rb +0 -83
  149. data/lib/pry/commands/gist.rb +0 -102
  150. data/lib/pry/commands/install_command.rb +0 -54
  151. data/lib/pry/config/behavior.rb +0 -255
  152. data/lib/pry/config/convenience.rb +0 -28
  153. data/lib/pry/config/default.rb +0 -159
  154. data/lib/pry/config/memoization.rb +0 -48
  155. data/lib/pry/platform.rb +0 -91
  156. data/lib/pry/plugins.rb +0 -122
  157. data/lib/pry/rubygem.rb +0 -84
  158. data/lib/pry/terminal.rb +0 -91
@@ -1,20 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Bang < Pry::ClassCommand
3
- match(/^\s*!\s*$/)
4
- group 'Editing'
5
- description 'Clear the input buffer.'
6
- command_options use_prefix: false
4
+ class Command
5
+ class Bang < Pry::ClassCommand
6
+ match(/^\s*!\s*$/)
7
+ group 'Editing'
8
+ description 'Clear the input buffer.'
9
+ command_options use_prefix: false, listing: '!'
7
10
 
8
- banner <<-'BANNER'
9
- Clear the input buffer. Useful if the parsing process goes wrong and you get
10
- stuck in the read loop.
11
- BANNER
11
+ banner <<-'BANNER'
12
+ Clear the input buffer. Useful if the parsing process goes wrong and you get
13
+ stuck in the read loop.
14
+ BANNER
12
15
 
13
- def process
14
- output.puts 'Input buffer cleared!'
15
- eval_string.replace('')
16
+ def process
17
+ output.puts 'Input buffer cleared!'
18
+ eval_string.replace('')
19
+ end
16
20
  end
17
- end
18
21
 
19
- Pry::Commands.add_command(Pry::Command::Bang)
22
+ Pry::Commands.add_command(Pry::Command::Bang)
23
+ end
20
24
  end
@@ -1,17 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::BangPry < Pry::ClassCommand
3
- match '!pry'
4
- group 'Navigating Pry'
5
- description 'Start a Pry session on current self.'
4
+ class Command
5
+ class BangPry < Pry::ClassCommand
6
+ match '!pry'
7
+ group 'Navigating Pry'
8
+ description 'Start a Pry session on current self.'
6
9
 
7
- banner <<-'BANNER'
8
- Start a Pry session on current self. Also works mid multi-line expression.
9
- BANNER
10
+ banner <<-'BANNER'
11
+ Start a Pry session on current self. Also works mid multi-line expression.
12
+ BANNER
10
13
 
11
- def process
12
- target.pry
14
+ def process
15
+ target.pry
16
+ end
13
17
  end
14
- end
15
18
 
16
- Pry::Commands.add_command(Pry::Command::BangPry)
19
+ Pry::Commands.add_command(Pry::Command::BangPry)
20
+ end
17
21
  end
@@ -1,63 +1,70 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Cat < Pry::ClassCommand
3
- require 'pry/commands/cat/abstract_formatter.rb'
4
- require 'pry/commands/cat/input_expression_formatter.rb'
5
- require 'pry/commands/cat/exception_formatter.rb'
6
- require 'pry/commands/cat/file_formatter.rb'
7
-
8
- match 'cat'
9
- group 'Input and Output'
10
- description "Show code from a file, Pry's input buffer, or the last exception."
11
-
12
- banner <<-'BANNER'
13
- Usage: cat FILE
14
- cat --ex [STACK_INDEX]
15
- cat --in [INPUT_INDEX_OR_RANGE]
16
-
17
- `cat` is capable of showing part or all of a source file, the context of the
18
- last exception, or an expression from Pry's input history.
19
-
20
- `cat --ex` defaults to showing the lines surrounding the location of the last
21
- exception. Invoking it more than once travels up the exception's backtrace, and
22
- providing a number shows the context of the given index of the backtrace.
23
- BANNER
24
-
25
- def options(opt)
26
- opt.on :ex, "Show the context of the last exception", optional_argument: true, as: Integer
27
- opt.on :i, :in, "Show one or more entries from Pry's expression history", optional_argument: true, as: Range, default: -5..-1
28
- opt.on :s, :start, "Starting line (defaults to the first line)", optional_argument: true, as: Integer
29
- opt.on :e, :end, "Ending line (defaults to the last line)", optional_argument: true, as: Integer
30
- opt.on :l, :'line-numbers', "Show line numbers"
31
- opt.on :t, :type, "The file type for syntax highlighting (e.g., 'ruby' or 'python')", argument: true, as: Symbol
32
- end
4
+ class Command
5
+ class Cat < Pry::ClassCommand
6
+ match 'cat'
7
+ group 'Input and Output'
8
+ description "Show code from a file, Pry's input buffer, or the last exception."
33
9
 
34
- def process
35
- output = case
36
- when opts.present?(:ex)
37
- ExceptionFormatter.new(_pry_.last_exception, _pry_, opts).format
38
- when opts.present?(:in)
39
- InputExpressionFormatter.new(_pry_.input_ring, opts).format
40
- else
41
- FileFormatter.new(args.first, _pry_, opts).format
42
- end
43
-
44
- _pry_.pager.page output
45
- end
10
+ banner <<-'BANNER'
11
+ Usage: cat FILE
12
+ cat --ex [STACK_INDEX]
13
+ cat --in [INPUT_INDEX_OR_RANGE]
46
14
 
47
- def complete(search)
48
- super | load_path_completions
49
- end
15
+ `cat` is capable of showing part or all of a source file, the context of the
16
+ last exception, or an expression from Pry's input history.
17
+
18
+ `cat --ex` defaults to showing the lines surrounding the location of the last
19
+ exception. Invoking it more than once travels up the exception's backtrace, and
20
+ providing a number shows the context of the given index of the backtrace.
21
+ BANNER
22
+
23
+ def options(opt)
24
+ opt.on :ex, "Show the context of the last exception",
25
+ optional_argument: true, as: Integer
26
+ opt.on :i, :in, "Show one or more entries from Pry's expression history",
27
+ optional_argument: true, as: Range, default: -5..-1
28
+ opt.on :s, :start, "Starting line (defaults to the first line)",
29
+ optional_argument: true, as: Integer
30
+ opt.on :e, :end, "Ending line (defaults to the last line)",
31
+ optional_argument: true, as: Integer
32
+ opt.on :l, :'line-numbers', "Show line numbers"
33
+ opt.on :t, :type, "The file type for syntax highlighting " \
34
+ "(e.g., 'ruby' or 'python')",
35
+ argument: true, as: Symbol
36
+ end
50
37
 
51
- def load_path_completions
52
- $LOAD_PATH.flat_map do |path|
53
- Dir[path + '/**/*'].map { |f|
54
- next if File.directory?(f)
38
+ def process
39
+ output =
40
+ if opts.present?(:ex)
41
+ ExceptionFormatter.new(
42
+ pry_instance.last_exception, pry_instance, opts
43
+ ).format
44
+ elsif opts.present?(:in)
45
+ InputExpressionFormatter.new(pry_instance.input_ring, opts).format
46
+ else
47
+ FileFormatter.new(args.first, pry_instance, opts).format
48
+ end
55
49
 
56
- f.sub!(path + '/', '')
57
- }
50
+ pry_instance.pager.page output
51
+ end
52
+
53
+ def complete(search)
54
+ super | load_path_completions
55
+ end
56
+
57
+ def load_path_completions
58
+ $LOAD_PATH.flat_map do |path|
59
+ Dir[path + '/**/*'].map do |f|
60
+ next if File.directory?(f)
61
+
62
+ f.sub!(path + '/', '')
63
+ end
64
+ end
58
65
  end
59
66
  end
60
- end
61
67
 
62
- Pry::Commands.add_command(Pry::Command::Cat)
68
+ Pry::Commands.add_command(Pry::Command::Cat)
69
+ end
63
70
  end
@@ -1,26 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Cat
3
- class AbstractFormatter
4
- include Pry::Helpers::CommandHelpers
5
- include Pry::Helpers::BaseHelpers
4
+ class Command
5
+ class Cat
6
+ class AbstractFormatter
7
+ include Pry::Helpers::CommandHelpers
8
+ include Pry::Helpers::BaseHelpers
6
9
 
7
- private
8
- def decorate(content)
9
- content.code_type = code_type
10
- content.between(*between_lines).
11
- with_line_numbers(use_line_numbers?).highlighted
12
- end
10
+ private
13
11
 
14
- def code_type
15
- opts[:type] || :ruby
16
- end
12
+ def decorate(content)
13
+ content.code_type = code_type
14
+ content.between(*between_lines)
15
+ .with_line_numbers(use_line_numbers?).highlighted
16
+ end
17
17
 
18
- def use_line_numbers?
19
- opts.present?(:'line-numbers') || opts.present?(:ex)
20
- end
18
+ def code_type
19
+ opts[:type] || :ruby
20
+ end
21
+
22
+ def use_line_numbers?
23
+ opts.present?(:'line-numbers') || opts.present?(:ex)
24
+ end
21
25
 
22
- def between_lines
23
- [opts[:start] || 1, opts[:end] || -1]
26
+ def between_lines
27
+ [opts[:start] || 1, opts[:end] || -1]
28
+ end
24
29
  end
25
30
  end
26
31
  end
@@ -1,78 +1,89 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Cat
3
- class ExceptionFormatter < AbstractFormatter
4
- attr_reader :ex
5
- attr_reader :opts
6
- attr_reader :_pry_
7
- include Pry::Helpers::Text
4
+ class Command
5
+ class Cat
6
+ class ExceptionFormatter < AbstractFormatter
7
+ attr_reader :ex
8
+ attr_reader :opts
9
+ attr_reader :pry_instance
10
+ include Pry::Helpers::Text
8
11
 
9
- def initialize(exception, _pry_, opts)
10
- @ex = exception
11
- @opts = opts
12
- @_pry_ = _pry_
13
- end
12
+ def initialize(exception, pry_instance, opts)
13
+ @ex = exception
14
+ @opts = opts
15
+ @pry_instance = pry_instance
16
+ end
14
17
 
15
- def format
16
- check_for_errors
17
- set_file_and_dir_locals(backtrace_file, _pry_, _pry_.current_context)
18
- code = decorate(Pry::Code.from_file(backtrace_file).
19
- between(*start_and_end_line_for_code_window).
20
- with_marker(backtrace_line))
21
- "#{header}#{code}"
22
- end
18
+ def format
19
+ check_for_errors
20
+ set_file_and_dir_locals(
21
+ backtrace_file, pry_instance, pry_instance.current_context
22
+ )
23
+ code = decorate(
24
+ Pry::Code.from_file(backtrace_file)
25
+ .between(*start_and_end_line_for_code_window)
26
+ .with_marker(backtrace_line)
27
+ )
28
+ "#{header}#{code}"
29
+ end
23
30
 
24
- private
31
+ private
25
32
 
26
- def code_window_size
27
- _pry_.config.default_window_size || 5
28
- end
33
+ def code_window_size
34
+ pry_instance.config.default_window_size || 5
35
+ end
29
36
 
30
- def backtrace_level
31
- @backtrace_level ||=
32
- begin
33
- bl =
34
- if opts[:ex].nil?
35
- ex.bt_index
36
- else
37
- ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
38
- end
37
+ def backtrace_level
38
+ @backtrace_level ||=
39
+ begin
40
+ bl =
41
+ if opts[:ex].nil?
42
+ ex.bt_index
43
+ else
44
+ ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
45
+ end
39
46
 
40
- increment_backtrace_level
41
- bl
42
- end
43
- end
47
+ increment_backtrace_level
48
+ bl
49
+ end
50
+ end
44
51
 
45
- def increment_backtrace_level
46
- ex.inc_bt_index
47
- end
52
+ def increment_backtrace_level
53
+ ex.inc_bt_index
54
+ end
48
55
 
49
- def backtrace_file
50
- Array(ex.bt_source_location_for(backtrace_level)).first
51
- end
56
+ def backtrace_file
57
+ Array(ex.bt_source_location_for(backtrace_level)).first
58
+ end
52
59
 
53
- def backtrace_line
54
- Array(ex.bt_source_location_for(backtrace_level)).last
55
- end
60
+ def backtrace_line
61
+ Array(ex.bt_source_location_for(backtrace_level)).last
62
+ end
56
63
 
57
- def check_for_errors
58
- raise CommandError, "No exception found." unless ex
59
- raise CommandError, "The given backtrace level is out of bounds." unless backtrace_file
60
- end
64
+ def check_for_errors
65
+ raise CommandError, "No exception found." unless ex
66
+ return if backtrace_file
61
67
 
62
- def start_and_end_line_for_code_window
63
- start_line = backtrace_line - code_window_size
64
- start_line = 1 if start_line < 1
68
+ raise CommandError, "The given backtrace level is out of bounds."
69
+ end
65
70
 
66
- [start_line, backtrace_line + code_window_size]
67
- end
71
+ def start_and_end_line_for_code_window
72
+ start_line = backtrace_line - code_window_size
73
+ start_line = 1 if start_line < 1
68
74
 
69
- def header
70
- unindent %{
71
- #{bold 'Exception:'} #{ex.class}: #{ex.message}
72
- --
73
- #{bold('From:')} #{backtrace_file} @ line #{backtrace_line} @ #{bold("level: #{backtrace_level}")} of backtrace (of #{ex.backtrace.size - 1}).
75
+ [start_line, backtrace_line + code_window_size]
76
+ end
74
77
 
75
- }
78
+ def header
79
+ unindent(
80
+ "#{bold 'Exception:'} #{ex.class}: #{ex.message}\n" \
81
+ "--\n" \
82
+ "#{bold('From:')} #{backtrace_file}:#{backtrace_line} @ " \
83
+ "#{bold("level: #{backtrace_level}")} of backtrace " \
84
+ "(of #{ex.backtrace.size - 1}).\n\n"
85
+ )
86
+ end
76
87
  end
77
88
  end
78
89
  end
@@ -1,69 +1,75 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Cat
3
- class FileFormatter < AbstractFormatter
4
- attr_reader :file_with_embedded_line
5
- attr_reader :opts
6
- attr_reader :_pry_
4
+ class Command
5
+ class Cat
6
+ class FileFormatter < AbstractFormatter
7
+ attr_reader :file_with_embedded_line
8
+ attr_reader :opts
9
+ attr_reader :pry_instance
7
10
 
8
- def initialize(file_with_embedded_line, _pry_, opts)
9
- raise CommandError, "Must provide a filename, --in, or --ex." if !file_with_embedded_line
11
+ def initialize(file_with_embedded_line, pry_instance, opts)
12
+ unless file_with_embedded_line
13
+ raise CommandError, "Must provide a filename, --in, or --ex."
14
+ end
10
15
 
11
- @file_with_embedded_line = file_with_embedded_line
12
- @opts = opts
13
- @_pry_ = _pry_
14
- @code_from_file = Pry::Code.from_file(file_name)
15
- end
16
+ @file_with_embedded_line = file_with_embedded_line
17
+ @opts = opts
18
+ @pry_instance = pry_instance
19
+ @code_from_file = Pry::Code.from_file(file_name)
20
+ end
16
21
 
17
- def format
18
- set_file_and_dir_locals(file_name, _pry_, _pry_.current_context)
19
- decorate(@code_from_file)
20
- end
22
+ def format
23
+ set_file_and_dir_locals(file_name, pry_instance, pry_instance.current_context)
24
+ decorate(@code_from_file)
25
+ end
21
26
 
22
- def file_and_line
23
- file_name, line_num = file_with_embedded_line.split(/:(?!\/|\\)/)
27
+ def file_and_line
28
+ file_name, line_num = file_with_embedded_line.split(%r{:(?!/|\\)})
24
29
 
25
- [file_name, line_num ? line_num.to_i : nil]
26
- end
30
+ [file_name, line_num ? line_num.to_i : nil]
31
+ end
27
32
 
28
- private
33
+ private
29
34
 
30
- def file_name
31
- file_and_line.first
32
- end
35
+ def file_name
36
+ file_and_line.first
37
+ end
33
38
 
34
- def line_number
35
- file_and_line.last
36
- end
39
+ def line_number
40
+ file_and_line.last
41
+ end
37
42
 
38
- def code_window_size
39
- _pry_.config.default_window_size || 7
40
- end
43
+ def code_window_size
44
+ pry_instance.config.default_window_size || 7
45
+ end
41
46
 
42
- def decorate(content)
43
- if line_number
44
- super(content.around(line_number, code_window_size))
45
- else
46
- super
47
+ def decorate(content)
48
+ if line_number
49
+ super(content.around(line_number, code_window_size))
50
+ else
51
+ super
52
+ end
47
53
  end
48
- end
49
54
 
50
- def code_type
51
- opts[:type] || detect_code_type_from_file(file_name)
52
- end
55
+ def code_type
56
+ opts[:type] || detect_code_type_from_file(file_name)
57
+ end
53
58
 
54
- def detect_code_type_from_file(file_name)
55
- code_type = @code_from_file.code_type
59
+ def detect_code_type_from_file(file_name)
60
+ code_type = @code_from_file.code_type
56
61
 
57
- if code_type == :unknown
58
- name = File.basename(file_name).split('.', 2).first
59
- case name
60
- when "Rakefile", "Gemfile"
61
- :ruby
62
+ if code_type == :unknown
63
+ name = File.basename(file_name).split('.', 2).first
64
+ case name
65
+ when "Rakefile", "Gemfile"
66
+ :ruby
67
+ else
68
+ :text
69
+ end
62
70
  else
63
- :text
71
+ code_type
64
72
  end
65
- else
66
- code_type
67
73
  end
68
74
  end
69
75
  end