chess_engine 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile.lock +21 -0
  4. data/README.md +26 -0
  5. data/chess_engine.gemspec +14 -0
  6. data/lib/chess_engine/board.rb +95 -0
  7. data/lib/chess_engine/cli.rb +105 -0
  8. data/lib/chess_engine/game.rb +148 -0
  9. data/lib/chess_engine/input.rb +19 -0
  10. data/lib/chess_engine/move.rb +35 -0
  11. data/lib/chess_engine/piece.rb +97 -0
  12. data/lib/chess_engine/validator.rb +87 -0
  13. data/lib/chess_engine.rb +1 -0
  14. data/spec/board_spec.rb +70 -0
  15. data/spec/game_helper.rb +5 -0
  16. data/spec/game_spec.rb +79 -0
  17. data/spec/spec_helper.rb +100 -0
  18. data/spec/validator_spec.rb +26 -0
  19. data/vendor/bundle/bin/coderay +27 -0
  20. data/vendor/bundle/bin/pry +27 -0
  21. data/vendor/bundle/cache/coderay-1.1.2.gem +0 -0
  22. data/vendor/bundle/cache/colorize-0.8.1.gem +0 -0
  23. data/vendor/bundle/cache/method_source-0.9.2.gem +0 -0
  24. data/vendor/bundle/cache/pry-0.12.2.gem +0 -0
  25. data/vendor/bundle/cache/rb-readline-0.5.5.gem +0 -0
  26. data/vendor/bundle/gems/coderay-1.1.2/MIT-LICENSE +22 -0
  27. data/vendor/bundle/gems/coderay-1.1.2/README_INDEX.rdoc +123 -0
  28. data/vendor/bundle/gems/coderay-1.1.2/bin/coderay +215 -0
  29. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/duo.rb +81 -0
  30. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/_map.rb +17 -0
  31. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/comment_filter.rb +25 -0
  32. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/count.rb +39 -0
  33. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug.rb +49 -0
  34. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug_lint.rb +63 -0
  35. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/div.rb +23 -0
  36. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/encoder.rb +190 -0
  37. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/filter.rb +58 -0
  38. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/css.rb +65 -0
  39. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/numbering.rb +108 -0
  40. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/output.rb +166 -0
  41. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html.rb +333 -0
  42. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/json.rb +83 -0
  43. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb +45 -0
  44. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lint.rb +59 -0
  45. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/null.rb +18 -0
  46. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/page.rb +24 -0
  47. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/span.rb +23 -0
  48. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/statistic.rb +95 -0
  49. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/terminal.rb +195 -0
  50. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/text.rb +46 -0
  51. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/token_kind_filter.rb +111 -0
  52. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/xml.rb +72 -0
  53. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/yaml.rb +50 -0
  54. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders.rb +18 -0
  55. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/for_redcloth.rb +95 -0
  56. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/file_type.rb +151 -0
  57. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin.rb +55 -0
  58. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin_host.rb +221 -0
  59. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/word_list.rb +72 -0
  60. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/_map.rb +24 -0
  61. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/c.rb +189 -0
  62. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/clojure.rb +217 -0
  63. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/cpp.rb +217 -0
  64. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/css.rb +196 -0
  65. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/debug.rb +75 -0
  66. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/delphi.rb +144 -0
  67. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/diff.rb +221 -0
  68. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/erb.rb +81 -0
  69. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/go.rb +208 -0
  70. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/groovy.rb +268 -0
  71. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/haml.rb +168 -0
  72. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/html.rb +275 -0
  73. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java/builtin_types.rb +421 -0
  74. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java.rb +174 -0
  75. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java_script.rb +237 -0
  76. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/json.rb +98 -0
  77. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/lua.rb +280 -0
  78. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/php.rb +527 -0
  79. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/python.rb +287 -0
  80. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/raydebug.rb +75 -0
  81. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/patterns.rb +178 -0
  82. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/string_state.rb +79 -0
  83. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby.rb +477 -0
  84. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sass.rb +232 -0
  85. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/scanner.rb +337 -0
  86. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sql.rb +169 -0
  87. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/taskpaper.rb +36 -0
  88. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/text.rb +26 -0
  89. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/xml.rb +17 -0
  90. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/yaml.rb +140 -0
  91. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners.rb +27 -0
  92. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/_map.rb +7 -0
  93. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/alpha.rb +153 -0
  94. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/style.rb +18 -0
  95. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles.rb +15 -0
  96. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/token_kinds.rb +85 -0
  97. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens.rb +161 -0
  98. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens_proxy.rb +55 -0
  99. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/version.rb +3 -0
  100. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay.rb +284 -0
  101. data/vendor/bundle/gems/colorize-0.8.1/CHANGELOG +65 -0
  102. data/vendor/bundle/gems/colorize-0.8.1/LICENSE +339 -0
  103. data/vendor/bundle/gems/colorize-0.8.1/README.md +105 -0
  104. data/vendor/bundle/gems/colorize-0.8.1/Rakefile +13 -0
  105. data/vendor/bundle/gems/colorize-0.8.1/colorize.gemspec +36 -0
  106. data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/class_methods.rb +120 -0
  107. data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/instance_methods.rb +132 -0
  108. data/vendor/bundle/gems/colorize-0.8.1/lib/colorize.rb +12 -0
  109. data/vendor/bundle/gems/colorize-0.8.1/lib/colorized_string.rb +19 -0
  110. data/vendor/bundle/gems/colorize-0.8.1/test/test_colorize.rb +164 -0
  111. data/vendor/bundle/gems/method_source-0.9.2/Gemfile +2 -0
  112. data/vendor/bundle/gems/method_source-0.9.2/LICENSE +25 -0
  113. data/vendor/bundle/gems/method_source-0.9.2/README.markdown +91 -0
  114. data/vendor/bundle/gems/method_source-0.9.2/Rakefile +81 -0
  115. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/code_helpers.rb +154 -0
  116. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/source_location.rb +138 -0
  117. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/version.rb +3 -0
  118. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source.rb +141 -0
  119. data/vendor/bundle/gems/method_source-0.9.2/method_source.gemspec +35 -0
  120. data/vendor/bundle/gems/method_source-0.9.2/spec/method_source/code_helpers_spec.rb +43 -0
  121. data/vendor/bundle/gems/method_source-0.9.2/spec/method_source_spec.rb +143 -0
  122. data/vendor/bundle/gems/method_source-0.9.2/spec/spec_helper.rb +101 -0
  123. data/vendor/bundle/gems/pry-0.12.2/CHANGELOG.md +953 -0
  124. data/vendor/bundle/gems/pry-0.12.2/LICENSE +25 -0
  125. data/vendor/bundle/gems/pry-0.12.2/README.md +390 -0
  126. data/vendor/bundle/gems/pry-0.12.2/bin/pry +8 -0
  127. data/vendor/bundle/gems/pry-0.12.2/lib/pry/basic_object.rb +6 -0
  128. data/vendor/bundle/gems/pry-0.12.2/lib/pry/cli.rb +218 -0
  129. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_file.rb +110 -0
  130. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_range.rb +71 -0
  131. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/loc.rb +98 -0
  132. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code.rb +353 -0
  133. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code_object.rb +195 -0
  134. data/vendor/bundle/gems/pry-0.12.2/lib/pry/color_printer.rb +65 -0
  135. data/vendor/bundle/gems/pry-0.12.2/lib/pry/command.rb +723 -0
  136. data/vendor/bundle/gems/pry-0.12.2/lib/pry/command_set.rb +415 -0
  137. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/amend_line.rb +98 -0
  138. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang.rb +20 -0
  139. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang_pry.rb +17 -0
  140. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  141. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/exception_formatter.rb +79 -0
  142. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/file_formatter.rb +71 -0
  143. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  144. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat.rb +63 -0
  145. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cd.rb +41 -0
  146. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_inspector.rb +27 -0
  147. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb +46 -0
  148. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/clear_screen.rb +14 -0
  149. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/code_collector.rb +167 -0
  150. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disable_pry.rb +27 -0
  151. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disabled_commands.rb +2 -0
  152. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/easter_eggs.rb +112 -0
  153. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/exception_patcher.rb +25 -0
  154. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  155. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit.rb +200 -0
  156. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit.rb +43 -0
  157. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_all.rb +29 -0
  158. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_program.rb +23 -0
  159. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/find_method.rb +191 -0
  160. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/fix_indent.rb +19 -0
  161. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_cd.rb +26 -0
  162. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_install.rb +32 -0
  163. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_list.rb +33 -0
  164. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_open.rb +29 -0
  165. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_readme.rb +25 -0
  166. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_search.rb +40 -0
  167. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_stats.rb +83 -0
  168. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gist.rb +102 -0
  169. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/help.rb +164 -0
  170. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/hist.rb +181 -0
  171. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/import_set.rb +23 -0
  172. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/install_command.rb +54 -0
  173. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/jump_to.rb +29 -0
  174. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/list_inspectors.rb +35 -0
  175. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/constants.rb +58 -0
  176. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/formatter.rb +51 -0
  177. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/globals.rb +46 -0
  178. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/grep.rb +19 -0
  179. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/instance_vars.rb +38 -0
  180. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/interrogatable.rb +18 -0
  181. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  182. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_names.rb +33 -0
  183. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_vars.rb +37 -0
  184. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/ls_entity.rb +69 -0
  185. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods.rb +54 -0
  186. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods_helper.rb +46 -0
  187. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/self_methods.rb +33 -0
  188. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls.rb +113 -0
  189. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/nesting.rb +25 -0
  190. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/play.rb +102 -0
  191. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_backtrace.rb +25 -0
  192. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_version.rb +17 -0
  193. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/raise_up.rb +33 -0
  194. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reload_code.rb +62 -0
  195. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reset.rb +18 -0
  196. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ri.rb +65 -0
  197. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/save_file.rb +61 -0
  198. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_command.rb +75 -0
  199. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_mode.rb +25 -0
  200. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_doc.rb +81 -0
  201. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_info.rb +216 -0
  202. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_input.rb +17 -0
  203. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_source.rb +53 -0
  204. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/stat.rb +40 -0
  205. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/switch_to.rb +23 -0
  206. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/toggle_color.rb +24 -0
  207. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression/expression.rb +38 -0
  208. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression.rb +107 -0
  209. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/whereami.rb +197 -0
  210. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/wtf.rb +70 -0
  211. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands.rb +6 -0
  212. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/behavior.rb +255 -0
  213. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/convenience.rb +28 -0
  214. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/default.rb +159 -0
  215. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/memoization.rb +48 -0
  216. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config.rb +35 -0
  217. data/vendor/bundle/gems/pry-0.12.2/lib/pry/core_extensions.rb +142 -0
  218. data/vendor/bundle/gems/pry-0.12.2/lib/pry/editor.rb +128 -0
  219. data/vendor/bundle/gems/pry-0.12.2/lib/pry/exceptions.rb +76 -0
  220. data/vendor/bundle/gems/pry-0.12.2/lib/pry/forwardable.rb +23 -0
  221. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/base_helpers.rb +200 -0
  222. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/command_helpers.rb +157 -0
  223. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/documentation_helpers.rb +76 -0
  224. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/options_helpers.rb +27 -0
  225. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/platform.rb +58 -0
  226. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/table.rb +114 -0
  227. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/text.rb +115 -0
  228. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers.rb +6 -0
  229. data/vendor/bundle/gems/pry-0.12.2/lib/pry/history.rb +161 -0
  230. data/vendor/bundle/gems/pry-0.12.2/lib/pry/hooks.rb +171 -0
  231. data/vendor/bundle/gems/pry-0.12.2/lib/pry/indent.rb +408 -0
  232. data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_completer.rb +265 -0
  233. data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_lock.rb +130 -0
  234. data/vendor/bundle/gems/pry-0.12.2/lib/pry/inspector.rb +27 -0
  235. data/vendor/bundle/gems/pry-0.12.2/lib/pry/last_exception.rb +61 -0
  236. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/disowned.rb +55 -0
  237. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/patcher.rb +122 -0
  238. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/weird_method_locator.rb +198 -0
  239. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method.rb +552 -0
  240. data/vendor/bundle/gems/pry-0.12.2/lib/pry/object_path.rb +83 -0
  241. data/vendor/bundle/gems/pry-0.12.2/lib/pry/output.rb +50 -0
  242. data/vendor/bundle/gems/pry-0.12.2/lib/pry/pager.rb +250 -0
  243. data/vendor/bundle/gems/pry-0.12.2/lib/pry/platform.rb +91 -0
  244. data/vendor/bundle/gems/pry-0.12.2/lib/pry/plugins.rb +122 -0
  245. data/vendor/bundle/gems/pry-0.12.2/lib/pry/prompt.rb +145 -0
  246. data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_class.rb +425 -0
  247. data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_instance.rb +699 -0
  248. data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl.rb +261 -0
  249. data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl_file_loader.rb +73 -0
  250. data/vendor/bundle/gems/pry-0.12.2/lib/pry/ring.rb +84 -0
  251. data/vendor/bundle/gems/pry-0.12.2/lib/pry/rubygem.rb +84 -0
  252. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/LICENSE +20 -0
  253. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/commands.rb +195 -0
  254. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/option.rb +206 -0
  255. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop.rb +661 -0
  256. data/vendor/bundle/gems/pry-0.12.2/lib/pry/terminal.rb +91 -0
  257. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/evalable.rb +15 -0
  258. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/mockable.rb +14 -0
  259. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/pry_tester.rb +73 -0
  260. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/utility.rb +26 -0
  261. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/variables.rb +46 -0
  262. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable.rb +70 -0
  263. data/vendor/bundle/gems/pry-0.12.2/lib/pry/version.rb +3 -0
  264. data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module/candidate.rb +131 -0
  265. data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module.rb +378 -0
  266. data/vendor/bundle/gems/pry-0.12.2/lib/pry.rb +132 -0
  267. data/vendor/bundle/gems/rb-readline-0.5.5/CHANGES +94 -0
  268. data/vendor/bundle/gems/rb-readline-0.5.5/LICENSE +25 -0
  269. data/vendor/bundle/gems/rb-readline-0.5.5/README.md +81 -0
  270. data/vendor/bundle/gems/rb-readline-0.5.5/Rakefile +25 -0
  271. data/vendor/bundle/gems/rb-readline-0.5.5/bench/_rl_adjust_point.rb +26 -0
  272. data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline.rb +8 -0
  273. data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline_with_completion.rb +18 -0
  274. data/vendor/bundle/gems/rb-readline-0.5.5/examples/tinyirb.rb +11 -0
  275. data/vendor/bundle/gems/rb-readline-0.5.5/lib/rb-readline.rb +18 -0
  276. data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline/version.rb +3 -0
  277. data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline.rb +8920 -0
  278. data/vendor/bundle/gems/rb-readline-0.5.5/lib/readline.rb +539 -0
  279. data/vendor/bundle/gems/rb-readline-0.5.5/rb-readline.gemspec +51 -0
  280. data/vendor/bundle/gems/rb-readline-0.5.5/setup.rb +1585 -0
  281. data/vendor/bundle/gems/rb-readline-0.5.5/test/support/filesystem_completion_helper.rb +53 -0
  282. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_completion.rb +100 -0
  283. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_filename_completion_proc.rb +88 -0
  284. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_history.rb +29 -0
  285. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_rbreadline.rb +23 -0
  286. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_readline.rb +221 -0
  287. data/vendor/bundle/specifications/coderay-1.1.2.gemspec +26 -0
  288. data/vendor/bundle/specifications/colorize-0.8.1.gemspec +38 -0
  289. data/vendor/bundle/specifications/method_source-0.9.2.gemspec +35 -0
  290. data/vendor/bundle/specifications/pry-0.12.2.gemspec +38 -0
  291. data/vendor/bundle/specifications/rb-readline-0.5.5.gemspec +39 -0
  292. metadata +363 -0
@@ -0,0 +1,699 @@
1
+ # -*- coding: utf-8 -*-
2
+ ##
3
+ # Pry is a powerful alternative to the standard IRB shell for Ruby. It
4
+ # features syntax highlighting, a flexible plugin architecture, runtime
5
+ # invocation and source and documentation browsing.
6
+ #
7
+ # Pry can be started similar to other command line utilities by simply running
8
+ # the following command:
9
+ #
10
+ # pry
11
+ #
12
+ # Once inside Pry you can invoke the help message:
13
+ #
14
+ # help
15
+ #
16
+ # This will show a list of available commands and their usage. For more
17
+ # information about Pry you can refer to the following resources:
18
+ #
19
+ # * http://pryrepl.org/
20
+ # * https://github.com/pry/pry
21
+ # * the IRC channel, which is #pry on the Freenode network
22
+ #
23
+
24
+ # rubocop:disable Metrics/ClassLength
25
+ class Pry
26
+ attr_accessor :binding_stack
27
+ attr_accessor :custom_completions
28
+ attr_accessor :eval_string
29
+ attr_accessor :backtrace
30
+ attr_accessor :suppress_output
31
+ attr_accessor :last_result
32
+ attr_accessor :last_file
33
+ attr_accessor :last_dir
34
+
35
+ attr_reader :last_exception
36
+ attr_reader :command_state
37
+ attr_reader :exit_value
38
+
39
+ # @since v0.12.0
40
+ attr_reader :input_ring
41
+
42
+ # @since v0.12.0
43
+ attr_reader :output_ring
44
+
45
+ attr_reader :config
46
+
47
+ extend Pry::Config::Convenience
48
+ config_shortcut(*Pry::Config.shortcuts)
49
+ EMPTY_COMPLETIONS = [].freeze
50
+
51
+ # Create a new {Pry} instance.
52
+ # @param [Hash] options
53
+ # @option options [#readline] :input
54
+ # The object to use for input.
55
+ # @option options [#puts] :output
56
+ # The object to use for output.
57
+ # @option options [Pry::CommandBase] :commands
58
+ # The object to use for commands.
59
+ # @option options [Hash] :hooks
60
+ # The defined hook Procs.
61
+ # @option options [Array<Proc>] :prompt
62
+ # The array of Procs to use for prompts.
63
+ # @option options [Proc] :print
64
+ # The Proc to use for printing return values.
65
+ # @option options [Boolean] :quiet
66
+ # Omit the `whereami` banner when starting.
67
+ # @option options [Array<String>] :backtrace
68
+ # The backtrace of the session's `binding.pry` line, if applicable.
69
+ # @option options [Object] :target
70
+ # The initial context for this session.
71
+ def initialize(options = {})
72
+ @binding_stack = []
73
+ @indent = Pry::Indent.new
74
+ @command_state = {}
75
+ @eval_string = ""
76
+ @backtrace = options.delete(:backtrace) || caller
77
+ target = options.delete(:target)
78
+ @config = Pry::Config.new
79
+ config.merge!(options)
80
+ push_prompt(config.prompt)
81
+ @input_ring = Pry::Ring.new(config.memory_size)
82
+ @output_ring = Pry::Ring.new(config.memory_size)
83
+ @custom_completions = config.command_completions
84
+ set_last_result nil
85
+ @input_ring << nil
86
+ push_initial_binding(target)
87
+ exec_hook(:when_started, target, options, self)
88
+ end
89
+
90
+ @input_array_warn = false
91
+ # @deprecated Use {#input_ring} instead.
92
+ def input_array
93
+ unless @input_array_warn
94
+ loc = caller_locations(1..1).first
95
+ warn(
96
+ "#{loc.path}:#{loc.lineno}: warning: method #{self.class}##{__method__} " \
97
+ "is deprecated. Use #{self.class}#input_ring instead"
98
+ )
99
+ @input_array_warn = true
100
+ end
101
+
102
+ @input_ring
103
+ end
104
+
105
+ @output_array_warn = false
106
+ # @deprecated Use {#output_ring} instead.
107
+ def output_array
108
+ unless @output_array_warn
109
+ loc = caller_locations(1..1).first
110
+ warn(
111
+ "#{loc.path}:#{loc.lineno}: warning: method #{self.class}##{__method__} " \
112
+ "is deprecated. Use #{self.class}#output_ring instead"
113
+ )
114
+ @output_array_warn = true
115
+ end
116
+
117
+ @output_ring
118
+ end
119
+
120
+ # This is the prompt at the top of the prompt stack.
121
+ # @return [Array<Proc>] the current prompt
122
+ def prompt
123
+ prompt_stack.last
124
+ end
125
+
126
+ def prompt=(new_prompt)
127
+ if prompt_stack.empty?
128
+ push_prompt new_prompt
129
+ else
130
+ prompt_stack[-1] = new_prompt
131
+ end
132
+ end
133
+
134
+ # Initialize this instance by pushing its initial context into the binding
135
+ # stack. If no target is given, start at the top level.
136
+ def push_initial_binding(target = nil)
137
+ push_binding(target || Pry.toplevel_binding)
138
+ end
139
+
140
+ # The currently active `Binding`.
141
+ # @return [Binding] The currently active `Binding` for the session.
142
+ def current_binding
143
+ binding_stack.last
144
+ end
145
+ alias current_context current_binding # support previous API
146
+
147
+ # Push a binding for the given object onto the stack. If this instance is
148
+ # currently stopped, mark it as usable again.
149
+ def push_binding(object)
150
+ @stopped = false
151
+ binding_stack << Pry.binding_for(object)
152
+ end
153
+
154
+ #
155
+ # Generate completions.
156
+ #
157
+ # @param [String] str
158
+ # What the user has typed so far
159
+ #
160
+ # @return [Array<String>]
161
+ # Possible completions
162
+ #
163
+ def complete(str)
164
+ return EMPTY_COMPLETIONS unless config.completer
165
+
166
+ Pry.critical_section do
167
+ completer = config.completer.new(config.input, self)
168
+ completer.call str, target: current_binding, custom_completions: custom_completions.call.push(*sticky_locals.keys)
169
+ end
170
+ end
171
+
172
+ #
173
+ # Injects a local variable into the provided binding.
174
+ #
175
+ # @param [String] name
176
+ # The name of the local to inject.
177
+ #
178
+ # @param [Object] value
179
+ # The value to set the local to.
180
+ #
181
+ # @param [Binding] b
182
+ # The binding to set the local on.
183
+ #
184
+ # @return [Object]
185
+ # The value the local was set to.
186
+ #
187
+ def inject_local(name, value, b)
188
+ value = Proc === value ? value.call : value
189
+ if b.respond_to?(:local_variable_set)
190
+ b.local_variable_set name, value
191
+ else # < 2.1
192
+ begin
193
+ Pry.current[:pry_local] = value
194
+ b.eval "#{name} = ::Pry.current[:pry_local]"
195
+ ensure
196
+ Pry.current[:pry_local] = nil
197
+ end
198
+ end
199
+ end
200
+
201
+ undef :memory_size if method_defined? :memory_size
202
+ # @return [Integer] The maximum amount of objects remembered by the inp and
203
+ # out arrays. Defaults to 100.
204
+ def memory_size
205
+ @output_ring.max_size
206
+ end
207
+
208
+ undef :memory_size= if method_defined? :memory_size=
209
+ def memory_size=(size)
210
+ @input_ring = Pry::Ring.new(size)
211
+ @output_ring = Pry::Ring.new(size)
212
+ end
213
+
214
+ # Inject all the sticky locals into the current binding.
215
+ def inject_sticky_locals!
216
+ sticky_locals.each_pair do |name, value|
217
+ inject_local(name, value, current_binding)
218
+ end
219
+ end
220
+
221
+ # Add a sticky local to this Pry instance.
222
+ # A sticky local is a local that persists between all bindings in a session.
223
+ # @param [Symbol] name The name of the sticky local.
224
+ # @yield The block that defines the content of the local. The local
225
+ # will be refreshed at each tick of the repl loop.
226
+ def add_sticky_local(name, &block)
227
+ config.extra_sticky_locals[name] = block
228
+ end
229
+
230
+ def sticky_locals
231
+ { _in_: input_ring,
232
+ _out_: output_ring,
233
+ _pry_: self,
234
+ _ex_: last_exception && last_exception.wrapped_exception,
235
+ _file_: last_file,
236
+ _dir_: last_dir,
237
+ _: proc { last_result },
238
+ __: proc { output_ring[-2] }
239
+ }.merge(config.extra_sticky_locals)
240
+ end
241
+
242
+ # Reset the current eval string. If the user has entered part of a multiline
243
+ # expression, this discards that input.
244
+ def reset_eval_string
245
+ @eval_string = ""
246
+ end
247
+
248
+ # Pass a line of input to Pry.
249
+ #
250
+ # This is the equivalent of `Binding#eval` but with extra Pry!
251
+ #
252
+ # In particular:
253
+ # 1. Pry commands will be executed immediately if the line matches.
254
+ # 2. Partial lines of input will be queued up until a complete expression has
255
+ # been accepted.
256
+ # 3. Output is written to `#output` in pretty colours, not returned.
257
+ #
258
+ # Once this method has raised an exception or returned false, this instance
259
+ # is no longer usable. {#exit_value} will return the session's breakout
260
+ # value if applicable.
261
+ #
262
+ # @param [String?] line The line of input; `nil` if the user types `<Ctrl-D>`
263
+ # @option options [Boolean] :generated Whether this line was generated automatically.
264
+ # Generated lines are not stored in history.
265
+ # @return [Boolean] Is Pry ready to accept more input?
266
+ # @raise [Exception] If the user uses the `raise-up` command, this method
267
+ # will raise that exception.
268
+ def eval(line, options = {})
269
+ return false if @stopped
270
+
271
+ exit_value = nil
272
+ exception = catch(:raise_up) do
273
+ exit_value = catch(:breakout) do
274
+ handle_line(line, options)
275
+ # We use 'return !@stopped' here instead of 'return true' so that if
276
+ # handle_line has stopped this pry instance (e.g. by opening _pry_.repl and
277
+ # then popping all the bindings) we still exit immediately.
278
+ return !@stopped
279
+ end
280
+ exception = false
281
+ end
282
+
283
+ @stopped = true
284
+ @exit_value = exit_value
285
+
286
+ # TODO: make this configurable?
287
+ raise exception if exception
288
+
289
+ return false
290
+ end
291
+
292
+ def handle_line(line, options)
293
+ if line.nil?
294
+ config.control_d_handler.call(@eval_string, self)
295
+ return
296
+ end
297
+
298
+ ensure_correct_encoding!(line)
299
+ Pry.history << line unless options[:generated]
300
+
301
+ @suppress_output = false
302
+ inject_sticky_locals!
303
+ begin
304
+ if !process_command_safely(line)
305
+ @eval_string << "#{line.chomp}\n" if !line.empty? || !@eval_string.empty?
306
+ end
307
+ rescue RescuableException => e
308
+ self.last_exception = e
309
+ result = e
310
+
311
+ Pry.critical_section do
312
+ show_result(result)
313
+ end
314
+ return
315
+ end
316
+
317
+ # This hook is supposed to be executed after each line of ruby code
318
+ # has been read (regardless of whether eval_string is yet a complete expression)
319
+ exec_hook :after_read, eval_string, self
320
+
321
+ begin
322
+ complete_expr = Pry::Code.complete_expression?(@eval_string)
323
+ rescue SyntaxError => e
324
+ output.puts "SyntaxError: #{e.message.sub(/.*syntax error, */m, '')}"
325
+ reset_eval_string
326
+ end
327
+
328
+ if complete_expr
329
+ if @eval_string =~ /;\Z/ || @eval_string.empty? || @eval_string =~ /\A *#.*\n\z/
330
+ @suppress_output = true
331
+ end
332
+
333
+ # A bug in jruby makes java.lang.Exception not rescued by
334
+ # `rescue Pry::RescuableException` clause.
335
+ #
336
+ # * https://github.com/pry/pry/issues/854
337
+ # * https://jira.codehaus.org/browse/JRUBY-7100
338
+ #
339
+ # Until that gets fixed upstream, treat java.lang.Exception
340
+ # as an additional exception to be rescued explicitly.
341
+ #
342
+ # This workaround has a side effect: java exceptions specified
343
+ # in `Pry.config.exception_whitelist` are ignored.
344
+ jruby_exceptions = []
345
+ if Helpers::Platform.jruby?
346
+ jruby_exceptions << Java::JavaLang::Exception
347
+ end
348
+
349
+ begin
350
+ # Reset eval string, in case we're evaluating Ruby that does something
351
+ # like open a nested REPL on this instance.
352
+ eval_string = @eval_string
353
+ reset_eval_string
354
+
355
+ result = evaluate_ruby(eval_string)
356
+ rescue RescuableException, *jruby_exceptions => e
357
+ # Eliminate following warning:
358
+ # warning: singleton on non-persistent Java type X
359
+ # (http://wiki.jruby.org/Persistence)
360
+ if Helpers::Platform.jruby? && e.class.respond_to?('__persistent__')
361
+ e.class.__persistent__ = true
362
+ end
363
+ self.last_exception = e
364
+ result = e
365
+ end
366
+
367
+ Pry.critical_section do
368
+ show_result(result)
369
+ end
370
+ end
371
+
372
+ throw(:breakout) if current_binding.nil?
373
+ end
374
+ private :handle_line
375
+
376
+ # Potentially deprecated — Use `Pry::REPL.new(pry, :target => target).start`
377
+ # (If nested sessions are going to exist, this method is fine, but a goal is
378
+ # to come up with an alternative to nested sessions altogether.)
379
+ def repl(target = nil)
380
+ Pry::REPL.new(self, target: target).start
381
+ end
382
+
383
+ def evaluate_ruby(code)
384
+ inject_sticky_locals!
385
+ exec_hook :before_eval, code, self
386
+
387
+ result = current_binding.eval(code, Pry.eval_path, Pry.current_line)
388
+ set_last_result(result, code)
389
+ ensure
390
+ update_input_history(code)
391
+ exec_hook :after_eval, result, self
392
+ end
393
+
394
+ # Output the result or pass to an exception handler (if result is an exception).
395
+ def show_result(result)
396
+ if last_result_is_exception?
397
+ exception_handler.call(output, result, self)
398
+ elsif should_print?
399
+ print.call(output, result, self)
400
+ else
401
+ # nothin'
402
+ end
403
+ rescue RescuableException => e
404
+ # Being uber-paranoid here, given that this exception arose because we couldn't
405
+ # serialize something in the user's program, let's not assume we can serialize
406
+ # the exception either.
407
+ begin
408
+ output.puts "(pry) output error: #{e.inspect}\n#{e.backtrace.join("\n")}"
409
+ rescue RescuableException => e
410
+ if last_result_is_exception?
411
+ output.puts "(pry) output error: failed to show exception"
412
+ else
413
+ output.puts "(pry) output error: failed to show result"
414
+ end
415
+ end
416
+ ensure
417
+ output.flush if output.respond_to?(:flush)
418
+ end
419
+
420
+ # Force `eval_string` into the encoding of `val`. [Issue #284]
421
+ def ensure_correct_encoding!(val)
422
+ if @eval_string.empty? &&
423
+ val.respond_to?(:encoding) &&
424
+ val.encoding != @eval_string.encoding
425
+ @eval_string.force_encoding(val.encoding)
426
+ end
427
+ end
428
+ private :ensure_correct_encoding!
429
+
430
+ # If the given line is a valid command, process it in the context of the
431
+ # current `eval_string` and binding.
432
+ # @param [String] val The line to process.
433
+ # @return [Boolean] `true` if `val` is a command, `false` otherwise
434
+ def process_command(val)
435
+ val = val.lstrip if /^\s\S/ !~ val
436
+ val = val.chomp
437
+ result = commands.process_line(val,
438
+ target: current_binding,
439
+ output: output,
440
+ eval_string: @eval_string,
441
+ pry_instance: self,
442
+ hooks: hooks
443
+ )
444
+
445
+ # set a temporary (just so we can inject the value we want into eval_string)
446
+ Pry.current[:pry_cmd_result] = result
447
+
448
+ # note that `result` wraps the result of command processing; if a
449
+ # command was matched and invoked then `result.command?` returns true,
450
+ # otherwise it returns false.
451
+ if result.command?
452
+ if !result.void_command?
453
+ # the command that was invoked was non-void (had a return value) and so we make
454
+ # the value of the current expression equal to the return value
455
+ # of the command.
456
+ @eval_string.replace "::Pry.current[:pry_cmd_result].retval\n"
457
+ end
458
+ true
459
+ else
460
+ false
461
+ end
462
+ end
463
+
464
+ # Same as process_command, but outputs exceptions to `#output` instead of
465
+ # raising.
466
+ # @param [String] val The line to process.
467
+ # @return [Boolean] `true` if `val` is a command, `false` otherwise
468
+ def process_command_safely(val)
469
+ process_command(val)
470
+ rescue CommandError, Pry::Slop::InvalidOptionError, MethodSource::SourceNotFoundError => e
471
+ Pry.last_internal_error = e
472
+ output.puts "Error: #{e.message}"
473
+ true
474
+ end
475
+
476
+ # Run the specified command.
477
+ # @param [String] val The command (and its params) to execute.
478
+ # @return [Pry::Command::VOID_VALUE]
479
+ # @example
480
+ # pry_instance.run_command("ls -m")
481
+ def run_command(val)
482
+ commands.process_line(val,
483
+ eval_string: @eval_string,
484
+ target: current_binding,
485
+ pry_instance: self,
486
+ output: output
487
+ )
488
+ Pry::Command::VOID_VALUE
489
+ end
490
+
491
+ # Execute the specified hook.
492
+ # @param [Symbol] name The hook name to execute
493
+ # @param [*Object] args The arguments to pass to the hook
494
+ # @return [Object, Exception] The return value of the hook or the exception raised
495
+ #
496
+ # If executing a hook raises an exception, we log that and then continue sucessfully.
497
+ # To debug such errors, use the global variable $pry_hook_error, which is set as a
498
+ # result.
499
+ def exec_hook(name, *args, &block)
500
+ e_before = hooks.errors.size
501
+ hooks.exec_hook(name, *args, &block).tap do
502
+ hooks.errors[e_before..-1].each do |e|
503
+ output.puts "#{name} hook failed: #{e.class}: #{e.message}"
504
+ output.puts "#{e.backtrace.first}"
505
+ output.puts "(see _pry_.hooks.errors to debug)"
506
+ end
507
+ end
508
+ end
509
+
510
+ # Set the last result of an eval.
511
+ # This method should not need to be invoked directly.
512
+ # @param [Object] result The result.
513
+ # @param [String] code The code that was run.
514
+ def set_last_result(result, code = "")
515
+ @last_result_is_exception = false
516
+ @output_ring << result
517
+
518
+ self.last_result = result unless code =~ /\A\s*\z/
519
+ end
520
+
521
+ #
522
+ # Set the last exception for a session.
523
+ #
524
+ # @param [Exception] e
525
+ # the last exception.
526
+ #
527
+ def last_exception=(e)
528
+ last_exception = Pry::LastException.new(e)
529
+ @last_result_is_exception = true
530
+ @output_ring << last_exception
531
+ @last_exception = last_exception
532
+ end
533
+
534
+ # Update Pry's internal state after evalling code.
535
+ # This method should not need to be invoked directly.
536
+ # @param [String] code The code we just eval'd
537
+ def update_input_history(code)
538
+ # Always push to the @input_ring as the @output_ring is always pushed to.
539
+ @input_ring << code
540
+ if code
541
+ Pry.line_buffer.push(*code.each_line)
542
+ Pry.current_line += code.lines.count
543
+ end
544
+ end
545
+
546
+ # @return [Boolean] True if the last result is an exception that was raised,
547
+ # as opposed to simply an instance of Exception (like the result of
548
+ # Exception.new)
549
+ def last_result_is_exception?
550
+ @last_result_is_exception
551
+ end
552
+
553
+ # Whether the print proc should be invoked.
554
+ # Currently only invoked if the output is not suppressed.
555
+ # @return [Boolean] Whether the print proc should be invoked.
556
+ def should_print?
557
+ !@suppress_output
558
+ end
559
+
560
+ # Returns the appropriate prompt to use.
561
+ # @return [String] The prompt.
562
+ def select_prompt
563
+ object = current_binding.eval('self')
564
+ open_token = @indent.open_delimiters.last || @indent.stack.last
565
+
566
+ c = Pry::Config.assign({
567
+ object: object,
568
+ nesting_level: binding_stack.size - 1,
569
+ open_token: open_token,
570
+ session_line: Pry.history.session_line_count + 1,
571
+ history_line: Pry.history.history_line_count + 1,
572
+ expr_number: input_ring.count,
573
+ _pry_: self,
574
+ binding_stack: binding_stack,
575
+ input_ring: input_ring,
576
+ eval_string: @eval_string,
577
+ cont: !@eval_string.empty?
578
+ })
579
+
580
+ Pry.critical_section do
581
+ # If input buffer is empty then use normal prompt
582
+ if eval_string.empty?
583
+ generate_prompt(Array(prompt).first, c)
584
+ # Otherwise use the wait prompt (indicating multi-line expression)
585
+ else
586
+ generate_prompt(Array(prompt).last, c)
587
+ end
588
+ end
589
+ end
590
+
591
+ def generate_prompt(prompt_proc, conf)
592
+ if prompt_proc.arity == 1
593
+ prompt_proc.call(conf)
594
+ else
595
+ prompt_proc.call(conf.object, conf.nesting_level, conf._pry_)
596
+ end
597
+ end
598
+ private :generate_prompt
599
+
600
+ # the array that the prompt stack is stored in
601
+ def prompt_stack
602
+ @prompt_stack ||= Array.new
603
+ end
604
+ private :prompt_stack
605
+
606
+ # Pushes the current prompt onto a stack that it can be restored from later.
607
+ # Use this if you wish to temporarily change the prompt.
608
+ # @param [Array<Proc>] new_prompt
609
+ # @return [Array<Proc>] new_prompt
610
+ # @example
611
+ # new_prompt = [ proc { '>' }, proc { '>>' } ]
612
+ # push_prompt(new_prompt) # => new_prompt
613
+ def push_prompt(new_prompt)
614
+ prompt_stack.push new_prompt
615
+ end
616
+
617
+ # Pops the current prompt off of the prompt stack.
618
+ # If the prompt you are popping is the last prompt, it will not be popped.
619
+ # Use this to restore the previous prompt.
620
+ # @return [Array<Proc>] Prompt being popped.
621
+ # @example
622
+ # prompt1 = [ proc { '>' }, proc { '>>' } ]
623
+ # prompt2 = [ proc { '$' }, proc { '>' } ]
624
+ # pry = Pry.new :prompt => prompt1
625
+ # pry.push_prompt(prompt2)
626
+ # pry.pop_prompt # => prompt2
627
+ # pry.pop_prompt # => prompt1
628
+ # pry.pop_prompt # => prompt1
629
+ def pop_prompt
630
+ prompt_stack.size > 1 ? prompt_stack.pop : prompt
631
+ end
632
+
633
+ undef :pager if method_defined? :pager
634
+ # Returns the currently configured pager
635
+ # @example
636
+ # _pry_.pager.page text
637
+ def pager
638
+ Pry::Pager.new(self)
639
+ end
640
+
641
+ undef :output if method_defined? :output
642
+ # Returns an output device
643
+ # @example
644
+ # _pry_.output.puts "ohai!"
645
+ def output
646
+ Pry::Output.new(self)
647
+ end
648
+
649
+ # Raise an exception out of Pry.
650
+ #
651
+ # See Kernel#raise for documentation of parameters.
652
+ # See rb_make_exception for the inbuilt implementation.
653
+ #
654
+ # This is necessary so that the raise-up command can tell the
655
+ # difference between an exception the user has decided to raise,
656
+ # and a mistake in specifying that exception.
657
+ #
658
+ # (i.e. raise-up RunThymeError.new should not be the same as
659
+ # raise-up NameError, "unititialized constant RunThymeError")
660
+ #
661
+ def raise_up_common(force, *args)
662
+ exception = if args == []
663
+ last_exception || RuntimeError.new
664
+ elsif args.length == 1 && args.first.is_a?(String)
665
+ RuntimeError.new(args.first)
666
+ elsif args.length > 3
667
+ raise ArgumentError, "wrong number of arguments"
668
+ elsif !args.first.respond_to?(:exception)
669
+ raise TypeError, "exception class/object expected"
670
+ elsif args.length === 1
671
+ args.first.exception
672
+ else
673
+ args.first.exception(args[1])
674
+ end
675
+
676
+ raise TypeError, "exception object expected" unless exception.is_a? Exception
677
+
678
+ exception.set_backtrace(args.length === 3 ? args[2] : caller(1))
679
+
680
+ if force || binding_stack.one?
681
+ binding_stack.clear
682
+ throw :raise_up, exception
683
+ else
684
+ binding_stack.pop
685
+ raise exception
686
+ end
687
+ end
688
+
689
+ def raise_up(*args); raise_up_common(false, *args); end
690
+
691
+ def raise_up!(*args); raise_up_common(true, *args); end
692
+
693
+ # Convenience accessor for the `quiet` config key.
694
+ # @return [Boolean]
695
+ def quiet?
696
+ config.quiet
697
+ end
698
+ end
699
+ # rubocop:enable Metrics/ClassLength