pry 0.11.3 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +346 -2
  3. data/LICENSE +1 -1
  4. data/README.md +351 -292
  5. data/bin/pry +1 -0
  6. data/lib/pry/basic_object.rb +8 -4
  7. data/lib/pry/block_command.rb +22 -0
  8. data/lib/pry/class_command.rb +194 -0
  9. data/lib/pry/cli.rb +58 -76
  10. data/lib/pry/code/code_file.rb +33 -28
  11. data/lib/pry/code/code_range.rb +7 -5
  12. data/lib/pry/code/loc.rb +26 -13
  13. data/lib/pry/code.rb +37 -33
  14. data/lib/pry/code_object.rb +41 -39
  15. data/lib/pry/color_printer.rb +47 -45
  16. data/lib/pry/command.rb +178 -374
  17. data/lib/pry/command_set.rb +89 -121
  18. data/lib/pry/command_state.rb +31 -0
  19. data/lib/pry/commands/amend_line.rb +86 -82
  20. data/lib/pry/commands/bang.rb +18 -14
  21. data/lib/pry/commands/bang_pry.rb +15 -11
  22. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  23. data/lib/pry/commands/cat/exception_formatter.rb +71 -59
  24. data/lib/pry/commands/cat/file_formatter.rb +55 -49
  25. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  26. data/lib/pry/commands/cat.rb +62 -54
  27. data/lib/pry/commands/cd.rb +40 -35
  28. data/lib/pry/commands/change_inspector.rb +29 -22
  29. data/lib/pry/commands/change_prompt.rb +48 -23
  30. data/lib/pry/commands/clear_screen.rb +20 -0
  31. data/lib/pry/commands/code_collector.rb +148 -133
  32. data/lib/pry/commands/disable_pry.rb +23 -19
  33. data/lib/pry/commands/easter_eggs.rb +19 -30
  34. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  35. data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
  36. data/lib/pry/commands/edit.rb +184 -160
  37. data/lib/pry/commands/exit.rb +40 -35
  38. data/lib/pry/commands/exit_all.rb +24 -20
  39. data/lib/pry/commands/exit_program.rb +20 -16
  40. data/lib/pry/commands/find_method.rb +168 -162
  41. data/lib/pry/commands/fix_indent.rb +16 -12
  42. data/lib/pry/commands/help.rb +140 -133
  43. data/lib/pry/commands/hist.rb +151 -149
  44. data/lib/pry/commands/import_set.rb +20 -15
  45. data/lib/pry/commands/jump_to.rb +25 -21
  46. data/lib/pry/commands/list_inspectors.rb +35 -28
  47. data/lib/pry/commands/ls/constants.rb +60 -43
  48. data/lib/pry/commands/ls/formatter.rb +42 -37
  49. data/lib/pry/commands/ls/globals.rb +38 -36
  50. data/lib/pry/commands/ls/grep.rb +17 -15
  51. data/lib/pry/commands/ls/instance_vars.rb +29 -28
  52. data/lib/pry/commands/ls/interrogatable.rb +18 -12
  53. data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
  54. data/lib/pry/commands/ls/local_names.rb +26 -24
  55. data/lib/pry/commands/ls/local_vars.rb +38 -30
  56. data/lib/pry/commands/ls/ls_entity.rb +47 -52
  57. data/lib/pry/commands/ls/methods.rb +49 -51
  58. data/lib/pry/commands/ls/methods_helper.rb +46 -42
  59. data/lib/pry/commands/ls/self_methods.rb +23 -23
  60. data/lib/pry/commands/ls.rb +124 -105
  61. data/lib/pry/commands/nesting.rb +21 -17
  62. data/lib/pry/commands/play.rb +92 -82
  63. data/lib/pry/commands/pry_backtrace.rb +22 -17
  64. data/lib/pry/commands/pry_version.rb +15 -11
  65. data/lib/pry/commands/raise_up.rb +33 -27
  66. data/lib/pry/commands/reload_code.rb +60 -48
  67. data/lib/pry/commands/reset.rb +16 -12
  68. data/lib/pry/commands/ri.rb +56 -45
  69. data/lib/pry/commands/save_file.rb +45 -43
  70. data/lib/pry/commands/shell_command.rb +52 -51
  71. data/lib/pry/commands/shell_mode.rb +22 -18
  72. data/lib/pry/commands/show_doc.rb +80 -70
  73. data/lib/pry/commands/show_info.rb +192 -167
  74. data/lib/pry/commands/show_input.rb +16 -11
  75. data/lib/pry/commands/show_source.rb +110 -42
  76. data/lib/pry/commands/stat.rb +35 -31
  77. data/lib/pry/commands/switch_to.rb +21 -15
  78. data/lib/pry/commands/toggle_color.rb +20 -16
  79. data/lib/pry/commands/watch_expression/expression.rb +32 -27
  80. data/lib/pry/commands/watch_expression.rb +89 -84
  81. data/lib/pry/commands/whereami.rb +156 -148
  82. data/lib/pry/commands/wtf.rb +78 -40
  83. data/lib/pry/config/attributable.rb +22 -0
  84. data/lib/pry/config/lazy_value.rb +29 -0
  85. data/lib/pry/config/memoized_value.rb +34 -0
  86. data/lib/pry/config/value.rb +24 -0
  87. data/lib/pry/config.rb +312 -9
  88. data/lib/pry/control_d_handler.rb +28 -0
  89. data/lib/pry/core_extensions.rb +13 -10
  90. data/lib/pry/editor.rb +56 -34
  91. data/lib/pry/env.rb +18 -0
  92. data/lib/pry/exception_handler.rb +43 -0
  93. data/lib/pry/exceptions.rb +13 -18
  94. data/lib/pry/forwardable.rb +5 -1
  95. data/lib/pry/helpers/base_helpers.rb +58 -58
  96. data/lib/pry/helpers/command_helpers.rb +52 -62
  97. data/lib/pry/helpers/documentation_helpers.rb +21 -13
  98. data/lib/pry/helpers/options_helpers.rb +14 -7
  99. data/lib/pry/helpers/platform.rb +55 -0
  100. data/lib/pry/helpers/table.rb +44 -32
  101. data/lib/pry/helpers/text.rb +20 -18
  102. data/lib/pry/helpers.rb +3 -0
  103. data/lib/pry/history.rb +65 -60
  104. data/lib/pry/hooks.rb +24 -15
  105. data/lib/pry/indent.rb +72 -70
  106. data/lib/pry/input_completer.rb +251 -228
  107. data/lib/pry/input_lock.rb +7 -10
  108. data/lib/pry/inspector.rb +36 -24
  109. data/lib/pry/last_exception.rb +45 -45
  110. data/lib/pry/method/disowned.rb +18 -5
  111. data/lib/pry/method/patcher.rb +14 -5
  112. data/lib/pry/method/weird_method_locator.rb +74 -51
  113. data/lib/pry/method.rb +175 -121
  114. data/lib/pry/object_path.rb +37 -28
  115. data/lib/pry/output.rb +122 -35
  116. data/lib/pry/pager.rb +187 -180
  117. data/lib/pry/prompt.rb +213 -25
  118. data/lib/pry/pry_class.rb +91 -96
  119. data/lib/pry/pry_instance.rb +258 -223
  120. data/lib/pry/repl.rb +49 -25
  121. data/lib/pry/repl_file_loader.rb +27 -22
  122. data/lib/pry/ring.rb +89 -0
  123. data/lib/pry/slop/commands.rb +164 -170
  124. data/lib/pry/slop/option.rb +172 -170
  125. data/lib/pry/slop.rb +567 -556
  126. data/lib/pry/syntax_highlighter.rb +26 -0
  127. data/lib/pry/system_command_handler.rb +17 -0
  128. data/lib/pry/testable/evalable.rb +21 -12
  129. data/lib/pry/testable/mockable.rb +18 -10
  130. data/lib/pry/testable/pry_tester.rb +71 -56
  131. data/lib/pry/testable/utility.rb +29 -21
  132. data/lib/pry/testable/variables.rb +49 -43
  133. data/lib/pry/testable.rb +59 -61
  134. data/lib/pry/version.rb +3 -1
  135. data/lib/pry/warning.rb +20 -0
  136. data/lib/pry/wrapped_module/candidate.rb +31 -23
  137. data/lib/pry/wrapped_module.rb +63 -59
  138. data/lib/pry.rb +132 -149
  139. metadata +39 -51
  140. data/lib/pry/commands/disabled_commands.rb +0 -2
  141. data/lib/pry/commands/gem_cd.rb +0 -26
  142. data/lib/pry/commands/gem_install.rb +0 -32
  143. data/lib/pry/commands/gem_list.rb +0 -33
  144. data/lib/pry/commands/gem_open.rb +0 -29
  145. data/lib/pry/commands/gem_readme.rb +0 -25
  146. data/lib/pry/commands/gem_search.rb +0 -40
  147. data/lib/pry/commands/gist.rb +0 -101
  148. data/lib/pry/commands/install_command.rb +0 -53
  149. data/lib/pry/commands/list_prompts.rb +0 -35
  150. data/lib/pry/commands/simple_prompt.rb +0 -22
  151. data/lib/pry/commands.rb +0 -6
  152. data/lib/pry/config/behavior.rb +0 -231
  153. data/lib/pry/config/convenience.rb +0 -25
  154. data/lib/pry/config/default.rb +0 -149
  155. data/lib/pry/config/memoization.rb +0 -44
  156. data/lib/pry/history_array.rb +0 -121
  157. data/lib/pry/platform.rb +0 -93
  158. data/lib/pry/plugins.rb +0 -118
  159. data/lib/pry/rbx_path.rb +0 -22
  160. data/lib/pry/rubygem.rb +0 -84
  161. data/lib/pry/terminal.rb +0 -90
@@ -1,164 +1,171 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Help < Pry::ClassCommand
3
- match 'help'
4
- group 'Help'
5
- description 'Show a list of commands or information about a specific command.'
6
-
7
- banner <<-'BANNER'
8
- Usage: help [COMMAND]
9
-
10
- With no arguments, help lists all the available commands along with their
11
- descriptions. When given a command name as an argument, shows the help
12
- for that command.
13
- BANNER
14
-
15
- # We only want to show commands that have descriptions, so that the
16
- # easter eggs don't show up.
17
- def visible_commands
18
- visible = {}
19
- commands.each do |key, command|
20
- visible[key] = command if command.description && !command.description.empty?
4
+ class Command
5
+ class Help < Pry::ClassCommand
6
+ match 'help'
7
+ group 'Help'
8
+ description 'Show a list of commands or information about a specific command.'
9
+
10
+ banner <<-'BANNER'
11
+ Usage: help [COMMAND]
12
+
13
+ With no arguments, help lists all the available commands along with their
14
+ descriptions. When given a command name as an argument, shows the help
15
+ for that command.
16
+ BANNER
17
+
18
+ # We only want to show commands that have descriptions, so that the
19
+ # easter eggs don't show up.
20
+ def visible_commands
21
+ visible = {}
22
+ commands.each do |key, command|
23
+ visible[key] = command if command.description && !command.description.empty?
24
+ end
25
+ visible
21
26
  end
22
- visible
23
- end
24
27
 
25
- # Get a hash of available commands grouped by the "group" name.
26
- def command_groups
27
- visible_commands.values.group_by(&:group)
28
- end
28
+ # Get a hash of available commands grouped by the "group" name.
29
+ def command_groups
30
+ visible_commands.values.group_by(&:group)
31
+ end
29
32
 
30
- def process
31
- if args.empty?
32
- display_index(command_groups)
33
- else
34
- display_search(args.first)
33
+ def process
34
+ if args.empty?
35
+ display_index(command_groups)
36
+ else
37
+ display_search(args.first)
38
+ end
35
39
  end
36
- end
37
40
 
38
- # Display the index view, with headings and short descriptions per command.
39
- #
40
- # @param [Hash<String, Array<Commands>>] groups
41
- def display_index(groups)
42
- help_text = []
41
+ # Display the index view, with headings and short descriptions per command.
42
+ #
43
+ # @param [Hash<String, Array<Commands>>] groups
44
+ def display_index(groups)
45
+ help_text = []
43
46
 
44
- sorted_group_names(groups).each do |group_name|
45
- commands = sorted_commands(groups[group_name])
47
+ sorted_group_names(groups).each do |group_name|
48
+ commands = sorted_commands(groups[group_name])
46
49
 
47
- if commands.any?
48
- help_text << help_text_for_commands(group_name, commands)
50
+ help_text << help_text_for_commands(group_name, commands) if commands.any?
49
51
  end
52
+
53
+ pry_instance.pager.page help_text.join("\n\n")
50
54
  end
51
55
 
52
- _pry_.pager.page help_text.join("\n\n")
53
- end
56
+ # Given a group name and an array of commands,
57
+ # return the help string for those commands.
58
+ #
59
+ # @param [String] name The group name.
60
+ # @param [Array<Pry::Command>] commands
61
+ # @return [String] The generated help string.
62
+ def help_text_for_commands(name, commands)
63
+ "#{bold(name.capitalize)}\n" + commands.map do |command|
64
+ " #{command.options[:listing].to_s.ljust(18)} " \
65
+ "#{command.description.capitalize}"
66
+ end.join("\n")
67
+ end
54
68
 
55
- # Given a group name and an array of commands,
56
- # return the help string for those commands.
57
- #
58
- # @param [String] name The group name.
59
- # @param [Array<Pry::Command>] commands
60
- # @return [String] The generated help string.
61
- def help_text_for_commands(name, commands)
62
- "#{text.bold(name.capitalize)}\n" << commands.map do |command|
63
- " #{command.options[:listing].to_s.ljust(18)} #{command.description.capitalize}"
64
- end.join("\n")
65
- end
69
+ # @param [Hash] groups
70
+ # @return [Array<String>] An array of sorted group names.
71
+ def sorted_group_names(groups)
72
+ groups.keys.sort_by(&method(:group_sort_key))
73
+ end
66
74
 
67
- # @param [Hash] groups
68
- # @return [Array<String>] An array of sorted group names.
69
- def sorted_group_names(groups)
70
- groups.keys.sort_by(&method(:group_sort_key))
71
- end
75
+ # Sort an array of commands by their `listing` name.
76
+ #
77
+ # @param [Array<Pry::Command>] commands The commands to sort
78
+ # @return [Array<Pry::Command>] commands sorted by listing name.
79
+ def sorted_commands(commands)
80
+ commands.sort_by { |command| command.options[:listing].to_s }
81
+ end
72
82
 
73
- # Sort an array of commands by their `listing` name.
74
- #
75
- # @param [Array<Pry::Command>] commands The commands to sort
76
- # @return [Array<Pry::Command>] commands sorted by listing name.
77
- def sorted_commands(commands)
78
- commands.sort_by{ |command| command.options[:listing].to_s }
79
- end
83
+ # Display help for an individual command or group.
84
+ #
85
+ # @param [String] search The string to search for.
86
+ def display_search(search)
87
+ if (command = command_set.find_command_for_help(search))
88
+ display_command(command)
89
+ else
90
+ display_filtered_search_results(search)
91
+ end
92
+ end
80
93
 
81
- # Display help for an individual command or group.
82
- #
83
- # @param [String] search The string to search for.
84
- def display_search(search)
85
- if command = command_set.find_command_for_help(search)
86
- display_command(command)
87
- else
88
- display_filtered_search_results(search)
94
+ # Display help for a searched item, filtered first by group
95
+ # and if that fails, filtered by command name.
96
+ #
97
+ # @param [String] search The string to search for.
98
+ def display_filtered_search_results(search)
99
+ groups = search_hash(search, command_groups)
100
+
101
+ if !groups.empty?
102
+ display_index(groups)
103
+ else
104
+ display_filtered_commands(search)
105
+ end
89
106
  end
90
- end
91
107
 
92
- # Display help for a searched item, filtered first by group
93
- # and if that fails, filtered by command name.
94
- #
95
- # @param [String] search The string to search for.
96
- def display_filtered_search_results(search)
97
- groups = search_hash(search, command_groups)
98
-
99
- if groups.size > 0
100
- display_index(groups)
101
- else
102
- display_filtered_commands(search)
108
+ # Display help for a searched item, filtered by group
109
+ #
110
+ # @param [String] search The string to search for.
111
+ def display_filtered_commands(search)
112
+ filtered = search_hash(search, visible_commands)
113
+ raise CommandError, "No help found for '#{args.first}'" if filtered.empty?
114
+
115
+ if filtered.size == 1
116
+ display_command(filtered.values.first)
117
+ else
118
+ display_index("'#{search}' commands" => filtered.values)
119
+ end
103
120
  end
104
- end
105
121
 
106
- # Display help for a searched item, filtered by group
107
- #
108
- # @param [String] search The string to search for.
109
- def display_filtered_commands(search)
110
- filtered = search_hash(search, visible_commands)
111
- raise CommandError, "No help found for '#{args.first}'" if filtered.empty?
112
-
113
- if filtered.size == 1
114
- display_command(filtered.values.first)
115
- else
116
- display_index({"'#{search}' commands" => filtered.values})
122
+ # Display help for an individual command.
123
+ #
124
+ # @param [Pry::Command] command
125
+ def display_command(command)
126
+ pry_instance.pager.page command.new.help
117
127
  end
118
- end
119
128
 
120
- # Display help for an individual command.
121
- #
122
- # @param [Pry::Command] command
123
- def display_command(command)
124
- _pry_.pager.page command.new.help
125
- end
129
+ # Find a subset of a hash that matches the user's search term.
130
+ #
131
+ # If there's an exact match a Hash of one element will be returned,
132
+ # otherwise a sub-Hash with every key that matches the search will
133
+ # be returned.
134
+ #
135
+ # @param [String] search the search term
136
+ # @param [Hash] hash the hash to search
137
+ def search_hash(search, hash)
138
+ matching = {}
139
+
140
+ hash.each_pair do |key, value|
141
+ next unless key.is_a?(String)
142
+ return { key => value } if normalize(key) == normalize(search)
143
+ next unless normalize(key).start_with?(normalize(search))
126
144
 
127
- # Find a subset of a hash that matches the user's search term.
128
- #
129
- # If there's an exact match a Hash of one element will be returned,
130
- # otherwise a sub-Hash with every key that matches the search will
131
- # be returned.
132
- #
133
- # @param [String] search the search term
134
- # @param [Hash] hash the hash to search
135
- def search_hash(search, hash)
136
- matching = {}
137
-
138
- hash.each_pair do |key, value|
139
- next unless key.is_a?(String)
140
- if normalize(key) == normalize(search)
141
- return {key => value}
142
- elsif normalize(key).start_with?(normalize(search))
143
145
  matching[key] = value
144
146
  end
147
+
148
+ matching
145
149
  end
146
150
 
147
- matching
148
- end
151
+ # Clean search terms to make it easier to search group names
152
+ #
153
+ # @param [String] key
154
+ # @return [String]
155
+ def normalize(key)
156
+ key.downcase.gsub(/pry\W+/, '')
157
+ end
149
158
 
150
- # Clean search terms to make it easier to search group names
151
- #
152
- # @param [String] key
153
- # @return [String]
154
- def normalize(key)
155
- key.downcase.gsub(/pry\W+/, '')
159
+ def group_sort_key(group_name)
160
+ [
161
+ %w[
162
+ Help Context Editing Introspection Input_and_output Navigating_pry
163
+ Gems Basic Commands
164
+ ].index(group_name.tr(' ', '_')) || 99, group_name
165
+ ]
166
+ end
156
167
  end
157
168
 
158
- def group_sort_key(group_name)
159
- [%w(Help Context Editing Introspection Input_and_output Navigating_pry Gems Basic Commands).index(group_name.gsub(' ', '_')) || 99, group_name]
160
- end
169
+ Pry::Commands.add_command(Pry::Command::Help)
161
170
  end
162
-
163
- Pry::Commands.add_command(Pry::Command::Help)
164
171
  end
@@ -1,180 +1,182 @@
1
- class Pry
2
- class Command::Hist < Pry::ClassCommand
3
- match 'hist'
4
- group 'Editing'
5
- description 'Show and replay Readline history.'
6
-
7
- banner <<-'BANNER'
8
- Usage: hist [--head|--tail]
9
- hist --all
10
- hist --head N
11
- hist --tail N
12
- hist --show START..END
13
- hist --grep PATTERN
14
- hist --clear
15
- hist --replay START..END
16
- hist --save [START..END] FILE
17
- Aliases: history
18
-
19
- Show and replay Readline history.
20
- BANNER
21
-
22
- def options(opt)
23
- opt.on :a, :all, "Display all history"
24
- opt.on :H, :head, "Display the first N items", :optional_argument => true, :as => Integer
25
- opt.on :T, :tail, "Display the last N items", :optional_argument => true, :as => Integer
26
- opt.on :s, :show, "Show the given range of lines", :optional_argument => true, :as => Range
27
- opt.on :G, :grep, "Show lines matching the given pattern", :argument => true, :as => String
28
- opt.on :c, :clear , "Clear the current session's history"
29
- opt.on :r, :replay, "Replay a line or range of lines", :argument => true, :as => Range
30
- opt.on :save, "Save history to a file", :argument => true, :as => Range
31
- opt.on :e, :'exclude-pry', "Exclude Pry commands from the history"
32
- opt.on :n, :'no-numbers', "Omit line numbers"
33
- end
34
-
35
- def process
36
- @history = find_history
1
+ # frozen_string_literal: true
37
2
 
38
- if opts.present?(:show)
39
- @history = @history.between(opts[:show])
3
+ class Pry
4
+ class Command
5
+ class Hist < Pry::ClassCommand
6
+ match 'hist'
7
+ group 'Editing'
8
+ description 'Show and replay Readline history.'
9
+
10
+ banner <<-'BANNER'
11
+ Usage: hist [--head|--tail]
12
+ hist --all
13
+ hist --head N
14
+ hist --tail N
15
+ hist --show START..END
16
+ hist --grep PATTERN
17
+ hist --clear
18
+ hist --replay START..END
19
+ hist --save [START..END] FILE
20
+ Aliases: history
21
+
22
+ Show and replay Readline history.
23
+ BANNER
24
+
25
+ def options(opt)
26
+ opt.on :a, :all, "Display all history"
27
+ opt.on :H, :head, "Display the first N items",
28
+ optional_argument: true, as: Integer
29
+ opt.on :T, :tail, "Display the last N items",
30
+ optional_argument: true, as: Integer
31
+ opt.on :s, :show, "Show the given range of lines",
32
+ optional_argument: true, as: Range
33
+ opt.on :G, :grep, "Show lines matching the given pattern",
34
+ argument: true, as: String
35
+ opt.on :c, :clear, "Clear the current session's history"
36
+ opt.on :r, :replay, "Replay a line or range of lines",
37
+ argument: true, as: Range
38
+ opt.on :save, "Save history to a file", argument: true, as: Range
39
+ opt.on :e, :'exclude-pry', "Exclude Pry commands from the history"
40
+ opt.on :n, :'no-numbers', "Omit line numbers"
40
41
  end
41
42
 
42
- if opts.present?(:grep)
43
- @history = @history.grep(opts[:grep])
44
- end
43
+ def process
44
+ @history = find_history
45
45
 
46
- @history = case
47
- when opts.present?(:head)
48
- @history.take_lines(1, opts[:head] || 10)
49
- when opts.present?(:tail)
50
- @history.take_lines(-(opts[:tail] || 10), opts[:tail] || 10)
51
- when opts.present?(:show)
52
- @history.between(opts[:show])
53
- else
54
- @history
55
- end
46
+ @history = @history.between(opts[:show]) if opts.present?(:show)
56
47
 
57
- if opts.present?(:'exclude-pry')
58
- @history = @history.select do |loc|
59
- !command_set.valid_command?(loc.line)
60
- end
61
- end
48
+ @history = @history.grep(opts[:grep]) if opts.present?(:grep)
62
49
 
63
- if opts.present?(:save)
64
- process_save
65
- elsif opts.present?(:clear)
66
- process_clear
67
- elsif opts.present?(:replay)
68
- process_replay
69
- else
70
- process_display
71
- end
72
- end
50
+ @history =
51
+ if opts.present?(:head)
52
+ @history.take_lines(1, opts[:head] || 10)
53
+ elsif opts.present?(:tail)
54
+ @history.take_lines(-(opts[:tail] || 10), opts[:tail] || 10)
55
+ else
56
+ @history
57
+ end
73
58
 
74
- private
59
+ if opts.present?(:'exclude-pry')
60
+ @history = @history.reject do |loc|
61
+ command_set.valid_command?(loc.line)
62
+ end
63
+ end
75
64
 
76
- def process_display
77
- unless opts.present?(:'no-numbers')
78
- @history = @history.with_line_numbers
65
+ if opts.present?(:save)
66
+ process_save
67
+ elsif opts.present?(:clear)
68
+ process_clear
69
+ elsif opts.present?(:replay)
70
+ process_replay
71
+ else
72
+ process_display
73
+ end
79
74
  end
80
75
 
81
- _pry_.pager.open do |pager|
82
- @history.print_to_output(pager, true)
83
- end
84
- end
76
+ private
85
77
 
86
- def process_save
87
- case opts[:save]
88
- when Range
89
- @history = @history.between(opts[:save])
78
+ def process_display
79
+ @history = @history.with_line_numbers unless opts.present?(:'no-numbers')
90
80
 
91
- unless args.first
92
- raise CommandError, "Must provide a file name."
81
+ pry_instance.pager.open do |pager|
82
+ @history.print_to_output(pager, true)
93
83
  end
94
-
95
- file_name = File.expand_path(args.first)
96
- when String
97
- file_name = File.expand_path(opts[:save])
98
84
  end
99
85
 
100
- output.puts "Saving history in #{file_name}..."
86
+ def process_save
87
+ case opts[:save]
88
+ when Range
89
+ @history = @history.between(opts[:save])
101
90
 
102
- File.open(file_name, 'w') { |f| f.write(@history.raw) }
91
+ raise CommandError, "Must provide a file name." unless args.first
103
92
 
104
- output.puts "History saved."
105
- end
93
+ file_name = File.expand_path(args.first)
94
+ when String
95
+ file_name = File.expand_path(opts[:save])
96
+ end
106
97
 
107
- def process_clear
108
- Pry.history.clear
109
- output.puts "History cleared."
110
- end
98
+ output.puts "Saving history in #{file_name}..."
111
99
 
112
- def process_replay
113
- @history = @history.between(opts[:r])
114
- replay_sequence = @history.raw
100
+ File.open(file_name, 'w') { |f| f.write(@history.raw) }
115
101
 
116
- # If we met follow-up "hist" call, check for the "--replay" option
117
- # presence. If "hist" command is called with other options, proceed
118
- # further.
119
- check_for_juxtaposed_replay(replay_sequence)
102
+ output.puts "History saved."
103
+ end
120
104
 
121
- replay_sequence.lines.each do |line|
122
- _pry_.eval line, :generated => true
105
+ def process_clear
106
+ Pry.history.clear
107
+ output.puts "History cleared."
123
108
  end
124
- end
125
109
 
126
- # Checks +replay_sequence+ for the presence of neighboring replay calls.
127
- # @example
128
- # [1] pry(main)> hist --show 46894
129
- # 46894: hist --replay 46675..46677
130
- # [2] pry(main)> hist --show 46675..46677
131
- # 46675: 1+1
132
- # 46676: a = 100
133
- # 46677: hist --tail
134
- # [3] pry(main)> hist --replay 46894
135
- # Error: Replay index 46894 points out to another replay call: `hist -r 46675..46677`
136
- # [4] pry(main)>
137
- #
138
- # @raise [Pry::CommandError] If +replay_sequence+ contains another
139
- # "hist --replay" call
140
- # @param [String] replay_sequence The sequence of commands to be replayed
141
- # (per saltum)
142
- # @return [Boolean] `false` if +replay_sequence+ does not contain another
143
- # "hist --replay" call
144
- def check_for_juxtaposed_replay(replay_sequence)
145
- if replay_sequence =~ /\Ahist(?:ory)?\b/
146
- # Create *fresh* instance of Options for parsing of "hist" command.
147
- _slop = self.slop
148
- _slop.parse replay_sequence.split(' ')[1..-1]
149
-
150
- if _slop.present?(:r)
151
- replay_sequence = replay_sequence.split("\n").join('; ')
152
- index = opts[:r]
153
- index = index.min if index.min == index.max || index.max.nil?
154
-
155
- raise CommandError, "Replay index #{ index } points out to another replay call: `#{ replay_sequence }`"
110
+ def process_replay
111
+ @history = @history.between(opts[:r])
112
+ replay_sequence = @history.raw
113
+
114
+ # If we met follow-up "hist" call, check for the "--replay" option
115
+ # presence. If "hist" command is called with other options, proceed
116
+ # further.
117
+ check_for_juxtaposed_replay(replay_sequence)
118
+
119
+ replay_sequence.lines.each do |line|
120
+ pry_instance.eval line, generated: true
156
121
  end
157
- else
158
- false
159
122
  end
160
- end
161
123
 
162
- # Finds history depending on the given switch.
163
- #
164
- # @return [Pry::Code] if it finds `--all` (or `-a`) switch, returns all
165
- # entries in history. Without the switch returns only the entries from the
166
- # current Pry session.
167
- def find_history
168
- h = if opts.present?(:all)
169
- Pry.history.to_a
170
- else
171
- Pry.history.to_a.last(Pry.history.session_line_count)
124
+ # Checks +replay_sequence+ for the presence of neighboring replay calls.
125
+ # @example
126
+ # [1] pry(main)> hist --show 46894
127
+ # 46894: hist --replay 46675..46677
128
+ # [2] pry(main)> hist --show 46675..46677
129
+ # 46675: 1+1
130
+ # 46676: a = 100
131
+ # 46677: hist --tail
132
+ # [3] pry(main)> hist --replay 46894
133
+ # Error: Replay index 46894 points out to another replay call:
134
+ # `hist -r 46675..46677`
135
+ # [4] pry(main)>
136
+ #
137
+ # @raise [Pry::CommandError] If +replay_sequence+ contains another
138
+ # "hist --replay" call
139
+ # @param [String] replay_sequence The sequence of commands to be replayed
140
+ # (per saltum)
141
+ # @return [Boolean] `false` if +replay_sequence+ does not contain another
142
+ # "hist --replay" call
143
+ def check_for_juxtaposed_replay(replay_sequence)
144
+ if replay_sequence =~ /\Ahist(?:ory)?\b/
145
+ # Create *fresh* instance of Options for parsing of "hist" command.
146
+ slop_instance = slop
147
+ slop_instance.parse(replay_sequence.split(' ')[1..-1])
148
+
149
+ if slop_instance.present?(:r)
150
+ replay_sequence = replay_sequence.split("\n").join('; ')
151
+ index = opts[:r]
152
+ index = index.min if index.min == index.max || index.max.nil?
153
+
154
+ raise CommandError,
155
+ "Replay index #{index} points out to another replay call: " \
156
+ "`#{replay_sequence}`"
172
157
  end
158
+ else
159
+ false
160
+ end
161
+ end
173
162
 
174
- Pry::Code(Pry.history.filter(h[0..-2]))
163
+ # Finds history depending on the given switch.
164
+ #
165
+ # @return [Pry::Code] if it finds `--all` (or `-a`) switch, returns all
166
+ # entries in history. Without the switch returns only the entries from the
167
+ # current Pry session.
168
+ def find_history
169
+ h = if opts.present?(:all)
170
+ Pry.history.to_a
171
+ else
172
+ Pry.history.to_a.last(Pry.history.session_line_count)
173
+ end
174
+
175
+ Pry::Code(Pry.history.filter(h[0..-2]))
176
+ end
175
177
  end
176
- end
177
178
 
178
- Pry::Commands.add_command(Pry::Command::Hist)
179
- Pry::Commands.alias_command 'history', 'hist'
179
+ Pry::Commands.add_command(Pry::Command::Hist)
180
+ Pry::Commands.alias_command 'history', 'hist'
181
+ end
180
182
  end