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,122 @@
1
+ class Pry
2
+ class PluginManager
3
+ PRY_PLUGIN_PREFIX = /^pry-/
4
+
5
+ # Placeholder when no associated gem found, displays warning
6
+ class NoPlugin
7
+ def initialize(name)
8
+ @name = name
9
+ end
10
+
11
+ def method_missing(*_args)
12
+ warn "Warning: The plugin '#{@name}' was not found! (no gem found)"
13
+ end
14
+ end
15
+
16
+ class Plugin
17
+ attr_accessor :name, :gem_name, :enabled, :spec, :active
18
+
19
+ def initialize(name, gem_name, spec, enabled)
20
+ @name, @gem_name, @enabled, @spec = name, gem_name, enabled, spec
21
+ end
22
+
23
+ # Disable a plugin. (prevents plugin from being loaded, cannot
24
+ # disable an already activated plugin)
25
+ def disable!
26
+ self.enabled = false
27
+ end
28
+
29
+ # Enable a plugin. (does not load it immediately but puts on
30
+ # 'white list' to be loaded)
31
+ def enable!
32
+ self.enabled = true
33
+ end
34
+
35
+ # Load the Command line options defined by this plugin (if they exist)
36
+ def load_cli_options
37
+ cli_options_file = File.join(spec.full_gem_path, "lib/#{spec.name}/cli.rb")
38
+ return unless File.exist?(cli_options_file)
39
+
40
+ cli_options_file = File.realpath(cli_options_file) if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4.4")
41
+ require cli_options_file
42
+ end
43
+
44
+ # Activate the plugin (require the gem - enables/loads the
45
+ # plugin immediately at point of call, even if plugin is
46
+ # disabled)
47
+ # Does not reload plugin if it's already active.
48
+ def activate!
49
+ # Create the configuration object for the plugin.
50
+ Pry.config.send("#{gem_name.gsub('-', '_')}=", Pry::Config.from_hash({}))
51
+
52
+ begin
53
+ require gem_name if !active?
54
+ rescue LoadError => e
55
+ warn "Found plugin #{gem_name}, but could not require '#{gem_name}'"
56
+ warn e
57
+ rescue => e
58
+ warn "require '#{gem_name}' # Failed, saying: #{e}"
59
+ end
60
+
61
+ self.active = true
62
+ self.enabled = true
63
+ end
64
+
65
+ alias active? active
66
+ alias enabled? enabled
67
+
68
+ def supported?
69
+ pry_version = Gem::Version.new(VERSION)
70
+ spec.dependencies.each do |dependency|
71
+ if dependency.name == "pry"
72
+ return dependency.requirement.satisfied_by?(pry_version)
73
+ end
74
+ end
75
+ true
76
+ end
77
+ end
78
+
79
+ def initialize
80
+ @plugins = []
81
+ end
82
+
83
+ # Find all installed Pry plugins and store them in an internal array.
84
+ def locate_plugins
85
+ gem_list.each do |gem|
86
+ next if gem.name !~ PRY_PLUGIN_PREFIX
87
+
88
+ plugin_name = gem.name.split('-', 2).last
89
+ plugin = Plugin.new(plugin_name, gem.name, gem, false)
90
+ @plugins << plugin.tap(&:enable!) if plugin.supported? && !plugin_located?(plugin)
91
+ end
92
+ @plugins
93
+ end
94
+
95
+ # @return [Hash] A hash with all plugin names (minus the 'pry-') as
96
+ # keys and Plugin objects as values.
97
+ def plugins
98
+ h = Hash.new { |_, key| NoPlugin.new(key) }
99
+ @plugins.each do |plugin|
100
+ h[plugin.name] = plugin
101
+ end
102
+ h
103
+ end
104
+
105
+ # Require all enabled plugins, disabled plugins are skipped.
106
+ def load_plugins
107
+ @plugins.each do |plugin|
108
+ plugin.activate! if plugin.enabled?
109
+ end
110
+ end
111
+
112
+ private
113
+ def plugin_located?(plugin)
114
+ @plugins.any? { |existing| existing.gem_name == plugin.gem_name }
115
+ end
116
+
117
+ def gem_list
118
+ Gem.refresh
119
+ Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,145 @@
1
+ class Pry
2
+ # Prompt represents the Pry prompt, which can be used with Readline-like
3
+ # libraries. It defines a few default prompts (default prompt, simple prompt,
4
+ # etc) and also provides an API to add custom prompts.
5
+ #
6
+ # @example
7
+ # Pry::Prompt.add(
8
+ # :ipython,
9
+ # 'IPython-like prompt', [':', '...:']
10
+ # ) do |_context, _nesting, _pry_, sep|
11
+ # sep == ':' ? "In [#{_pry_.input_ring.count}]: " : ' ...: '
12
+ # end
13
+ #
14
+ # # Produces:
15
+ # # In [3]: def foo
16
+ # # ...: puts 'foo'
17
+ # # ...: end
18
+ # # => :foo
19
+ # # In [4]:
20
+ # @since v0.11.0
21
+ # @api public
22
+ module Prompt
23
+ # @return [String]
24
+ DEFAULT_NAME = 'pry'.freeze
25
+
26
+ # @return [Array<Object>] the list of objects that are known to have a
27
+ # 1-line #inspect output suitable for prompt
28
+ SAFE_CONTEXTS = [String, Numeric, Symbol, nil, true, false].freeze
29
+
30
+ # @deprecated Use {Pry::Prompt.add} instead.
31
+ MAP = {}
32
+ deprecate_constant(:MAP) if respond_to?(:deprecate_constant)
33
+
34
+ # A Hash that holds all prompts. The keys of the Hash are prompt
35
+ # names, the values are Hash instances of the format {:description, :value}.
36
+ @prompts = {}
37
+
38
+ class << self
39
+ # Retrieves a prompt.
40
+ #
41
+ # @example
42
+ # Prompt[:my_prompt][:value]
43
+ #
44
+ # @param [Symbol] prompt_name The name of the prompt you want to access
45
+ # @return [Hash{Symbol=>Object}]
46
+ # @since v0.12.0
47
+ def [](prompt_name)
48
+ @prompts[prompt_name.to_s]
49
+ end
50
+
51
+ # @return [Hash{Symbol=>Hash}] the duplicate of the internal prompts hash
52
+ # @note Use this for read-only operations
53
+ # @since v0.12.0
54
+ def all
55
+ @prompts.dup
56
+ end
57
+
58
+ # Adds a new prompt to the prompt hash.
59
+ #
60
+ # @param [Symbol] prompt_name
61
+ # @param [String] description
62
+ # @param [Array<String>] separators The separators to differentiate
63
+ # between prompt modes (default mode and class/method definition mode).
64
+ # The Array *must* have a size of 2.
65
+ # @yield [context, nesting, _pry_, sep]
66
+ # @yieldparam context [Object] the context where Pry is currently in
67
+ # @yieldparam nesting [Integer] whether the context is nested
68
+ # @yieldparam _pry_ [Pry] the Pry instance
69
+ # @yieldparam separator [String] separator string
70
+ # @return [nil]
71
+ # @raise [ArgumentError] if the size of `separators` is not 2
72
+ # @since v0.12.0
73
+ def add(prompt_name, description = '', separators = %w[> *])
74
+ unless separators.size == 2
75
+ raise ArgumentError, "separators size must be 2, given #{separators.size}"
76
+ end
77
+
78
+ @prompts[prompt_name.to_s] = {
79
+ description: description,
80
+ value: separators.map do |sep|
81
+ proc { |context, nesting, _pry_| yield(context, nesting, _pry_, sep) }
82
+ end
83
+ }
84
+
85
+ nil
86
+ end
87
+
88
+ private
89
+
90
+ def prompt_name(name)
91
+ return name unless name.is_a?(Pry::Config::Lazy)
92
+
93
+ name.call
94
+ end
95
+ end
96
+
97
+ add(:default, <<DESC) do |context, nesting, _pry_, sep|
98
+ The default Pry prompt. Includes information about the current expression
99
+ number, evaluation context, and nesting level, plus a reminder that you're
100
+ using Pry.
101
+ DESC
102
+ format(
103
+ "[%<in_count>s] %<name>s(%<context>s)%<nesting>s%<separator>s ",
104
+ in_count: _pry_.input_ring.count,
105
+ name: prompt_name(_pry_.config.prompt_name),
106
+ context: Pry.view_clip(context),
107
+ nesting: (nesting > 0 ? ":#{nesting}" : ''),
108
+ separator: sep
109
+ )
110
+ end
111
+
112
+ add(:simple, "A simple `>>`.\n", ['>> ', ' | ']) do |_, _, _, sep|
113
+ sep
114
+ end
115
+
116
+ add(:nav, <<DESC, %w[> *]) do |context, nesting, _pry_, sep|
117
+ A prompt that displays the binding stack as a path and includes information
118
+ about #{Helpers::Text.bold('_in_')} and #{Helpers::Text.bold('_out_')}.
119
+ DESC
120
+ tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval('self')) }
121
+ format(
122
+ "[%<in_count>s] (%<name>s) %<tree>s: %<stack_size>s%<separator>s ",
123
+ in_count: _pry_.input_ring.count,
124
+ name: prompt_name(_pry_.config.prompt_name),
125
+ tree: tree.join(' / '),
126
+ stack_size: _pry_.binding_stack.size - 1,
127
+ separator: sep
128
+ )
129
+ end
130
+
131
+ add(:shell, <<DESC, %w[$ *]) do |context, nesting, _pry_, sep|
132
+ A prompt that displays `$PWD` as you change it.
133
+ DESC
134
+ format(
135
+ "%<name>s %<context>s:%<pwd>s %<separator>s ",
136
+ name: prompt_name(_pry_.config.prompt_name),
137
+ context: Pry.view_clip(context),
138
+ pwd: Dir.pwd,
139
+ separator: sep
140
+ )
141
+ end
142
+
143
+ add(:none, 'Wave goodbye to the Pry prompt.', Array.new(2)) { '' }
144
+ end
145
+ end
@@ -0,0 +1,425 @@
1
+ class Pry
2
+ HOME_RC_FILE =
3
+ if ENV.key?('PRYRC')
4
+ ENV['PRYRC']
5
+ elsif File.exist?(File.expand_path('~/.pryrc'))
6
+ '~/.pryrc'
7
+ elsif ENV.key?('XDG_CONFIG_HOME') && ENV['XDG_CONFIG_HOME'] != ''
8
+ # See XDG Base Directory Specification at
9
+ # https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
10
+ ENV['XDG_CONFIG_HOME'] + '/pry/pryrc'
11
+ else
12
+ '~/.config/pry/pryrc'
13
+ end
14
+ LOCAL_RC_FILE = "./.pryrc"
15
+
16
+ class << self
17
+ extend Pry::Forwardable
18
+ attr_accessor :custom_completions
19
+ attr_accessor :current_line
20
+ attr_accessor :line_buffer
21
+ attr_accessor :eval_path
22
+ attr_accessor :cli
23
+ attr_accessor :quiet
24
+ attr_accessor :last_internal_error
25
+ attr_accessor :config
26
+ attr_writer :history
27
+
28
+ def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
29
+
30
+ extend Pry::Config::Convenience
31
+ config_shortcut(*Pry::Config.shortcuts)
32
+
33
+ def prompt=(value)
34
+ config.prompt = value
35
+ end
36
+
37
+ def prompt
38
+ config.prompt
39
+ end
40
+
41
+ def history
42
+ @history ||= History.new
43
+ end
44
+
45
+ #
46
+ # @example
47
+ # Pry.configure do |config|
48
+ # config.eager_load! # optional
49
+ # config.input = # ..
50
+ # config.foo = 2
51
+ # end
52
+ #
53
+ # @yield [config]
54
+ # Yields a block with {Pry.config} as its argument.
55
+ #
56
+ def configure
57
+ yield config
58
+ end
59
+ end
60
+
61
+ #
62
+ # @return [main]
63
+ # returns the special instance of Object, "main".
64
+ #
65
+ def self.main
66
+ @main ||= TOPLEVEL_BINDING.eval "self"
67
+ end
68
+
69
+ #
70
+ # @return [Pry::Config]
71
+ # Returns a value store for an instance of Pry running on the current thread.
72
+ #
73
+ def self.current
74
+ Thread.current[:__pry__] ||= Pry::Config.from_hash({}, nil)
75
+ end
76
+
77
+ # Load the given file in the context of `Pry.toplevel_binding`
78
+ # @param [String] file The unexpanded file path.
79
+ def self.load_file_at_toplevel(file)
80
+ toplevel_binding.eval(File.read(file), file)
81
+ rescue RescuableException => e
82
+ puts "Error loading #{file}: #{e}\n#{e.backtrace.first}"
83
+ end
84
+
85
+ # Load HOME_RC_FILE and LOCAL_RC_FILE if appropriate
86
+ # This method can also be used to reload the files if they have changed.
87
+ def self.load_rc_files
88
+ rc_files_to_load.each do |file|
89
+ critical_section do
90
+ load_file_at_toplevel(file)
91
+ end
92
+ end
93
+ end
94
+
95
+ # Load the local RC file (./.pryrc)
96
+ def self.rc_files_to_load
97
+ files = []
98
+ files << HOME_RC_FILE if Pry.config.should_load_rc
99
+ files << LOCAL_RC_FILE if Pry.config.should_load_local_rc
100
+ files.map { |file| real_path_to(file) }.compact.uniq
101
+ end
102
+
103
+ # Expand a file to its canonical name (following symlinks as appropriate)
104
+ def self.real_path_to(file)
105
+ Pathname.new(File.expand_path(file)).realpath.to_s
106
+ rescue Errno::ENOENT, Errno::EACCES
107
+ nil
108
+ end
109
+
110
+ # Load any Ruby files specified with the -r flag on the command line.
111
+ def self.load_requires
112
+ Pry.config.requires.each do |file|
113
+ require file
114
+ end
115
+ end
116
+
117
+ # Trap interrupts on jruby, and make them behave like MRI so we can
118
+ # catch them.
119
+ def self.load_traps
120
+ trap('INT') { raise Interrupt }
121
+ end
122
+
123
+ def self.load_win32console
124
+ begin
125
+ require 'win32console'
126
+ # The mswin and mingw versions of pry require win32console, so this should
127
+ # only fail on jruby (where win32console doesn't work).
128
+ # Instead we'll recommend ansicon, which does.
129
+ rescue LoadError
130
+ warn <<-WARNING if Pry.config.windows_console_warning
131
+ For a better Pry experience on Windows, please use ansicon:
132
+ https://github.com/adoxa/ansicon
133
+ If you use an alternative to ansicon and don't want to see this warning again,
134
+ you can add "Pry.config.windows_console_warning = false" to your pryrc.
135
+ WARNING
136
+ end
137
+ end
138
+
139
+ # Do basic setup for initial session including: loading pryrc, plugins,
140
+ # requires, and history.
141
+ def self.initial_session_setup
142
+ return unless initial_session?
143
+
144
+ @initial_session = false
145
+
146
+ # note these have to be loaded here rather than in pry_instance as
147
+ # we only want them loaded once per entire Pry lifetime.
148
+ load_rc_files
149
+ end
150
+
151
+ def self.final_session_setup
152
+ return if @session_finalized
153
+
154
+ @session_finalized = true
155
+ load_plugins if Pry.config.should_load_plugins
156
+ load_requires if Pry.config.should_load_requires
157
+ load_history if Pry.config.history.should_load
158
+ load_traps if Pry.config.should_trap_interrupts
159
+ load_win32console if Helpers::Platform.windows? && !Helpers::Platform.windows_ansi?
160
+ end
161
+
162
+ # Start a Pry REPL.
163
+ # This method also loads `pryrc` as necessary the first time it is invoked.
164
+ # @param [Object, Binding] target The receiver of the Pry session
165
+ # @param [Hash] options
166
+ # @option options (see Pry#initialize)
167
+ # @example
168
+ # Pry.start(Object.new, :input => MyInput.new)
169
+ def self.start(target = nil, options = {})
170
+ return if ENV['DISABLE_PRY']
171
+ if ENV['FAIL_PRY']
172
+ raise 'You have FAIL_PRY set to true, which results in Pry calls failing'
173
+ end
174
+
175
+ options = options.to_hash
176
+
177
+ if in_critical_section?
178
+ output.puts "ERROR: Pry started inside Pry."
179
+ output.puts "This can happen if you have a binding.pry inside a #to_s or #inspect function."
180
+ return
181
+ end
182
+
183
+ options[:target] = Pry.binding_for(target || toplevel_binding)
184
+ initial_session_setup
185
+ final_session_setup
186
+
187
+ # Unless we were given a backtrace, save the current one
188
+ if options[:backtrace].nil?
189
+ options[:backtrace] = caller
190
+
191
+ # If Pry was started via `binding.pry`, elide that from the backtrace
192
+ if options[:backtrace].first =~ /pry.*core_extensions.*pry/
193
+ options[:backtrace].shift
194
+ end
195
+ end
196
+
197
+ driver = options[:driver] || Pry::REPL
198
+
199
+ # Enter the matrix
200
+ driver.start(options)
201
+ rescue Pry::TooSafeException
202
+ puts "ERROR: Pry cannot work with $SAFE > 0"
203
+ raise
204
+ end
205
+
206
+ # Execute the file through the REPL loop, non-interactively.
207
+ # @param [String] file_name File name to load through the REPL.
208
+ def self.load_file_through_repl(file_name)
209
+ require "pry/repl_file_loader"
210
+ REPLFileLoader.new(file_name).load
211
+ end
212
+
213
+ #
214
+ # An inspector that clips the output to `max_length` chars.
215
+ # In case of > `max_length` chars the `#<Object...> notation is used.
216
+ #
217
+ # @param [Object] obj
218
+ # The object to view.
219
+ #
220
+ # @param [Hash] options
221
+ # @option options [Integer] :max_length (60)
222
+ # The maximum number of chars before clipping occurs.
223
+ #
224
+ # @option options [Boolean] :id (false)
225
+ # Boolean to indicate whether or not a hex reprsentation of the object ID
226
+ # is attached to the return value when the length of inspect is greater than
227
+ # value of `:max_length`.
228
+ #
229
+ # @return [String]
230
+ # The string representation of `obj`.
231
+ #
232
+ def self.view_clip(obj, options = {})
233
+ max = options.fetch :max_length, 60
234
+ id = options.fetch :id, false
235
+ if obj.kind_of?(Module) && obj.name.to_s != "" && obj.name.to_s.length <= max
236
+ obj.name.to_s
237
+ elsif Pry.main == obj
238
+ # special-case to support jruby.
239
+ # fixed as of https://github.com/jruby/jruby/commit/d365ebd309cf9df3dde28f5eb36ea97056e0c039
240
+ # we can drop in the future.
241
+ obj.to_s
242
+ elsif Pry.config.prompt_safe_contexts.any? { |v| v === obj } && obj.inspect.length <= max
243
+ obj.inspect
244
+ else
245
+ id == true ? "#<#{obj.class}:0x%x>" % (obj.object_id << 1) : "#<#{obj.class}>"
246
+ end
247
+ rescue RescuableException
248
+ "unknown"
249
+ end
250
+
251
+ # Load Readline history if required.
252
+ def self.load_history
253
+ Pry.history.load
254
+ end
255
+
256
+ # @return [Boolean] Whether this is the first time a Pry session has
257
+ # been started since loading the Pry class.
258
+ def self.initial_session?
259
+ @initial_session
260
+ end
261
+
262
+ # Run a Pry command from outside a session. The commands available are
263
+ # those referenced by `Pry.config.commands` (the default command set).
264
+ # @param [String] command_string The Pry command (including arguments,
265
+ # if any).
266
+ # @param [Hash] options Optional named parameters.
267
+ # @return [nil]
268
+ # @option options [Object, Binding] :target The object to run the
269
+ # command under. Defaults to `TOPLEVEL_BINDING` (main).
270
+ # @option options [Boolean] :show_output Whether to show command
271
+ # output. Defaults to true.
272
+ # @example Run at top-level with no output.
273
+ # Pry.run_command "ls"
274
+ # @example Run under Pry class, returning only public methods.
275
+ # Pry.run_command "ls -m", :target => Pry
276
+ # @example Display command output.
277
+ # Pry.run_command "ls -av", :show_output => true
278
+ def self.run_command(command_string, options = {})
279
+ options = {
280
+ target: TOPLEVEL_BINDING,
281
+ show_output: true,
282
+ output: Pry.config.output,
283
+ commands: Pry.config.commands
284
+ }.merge!(options)
285
+
286
+ # :context for compatibility with <= 0.9.11.4
287
+ target = options[:context] || options[:target]
288
+ output = options[:show_output] ? options[:output] : StringIO.new
289
+
290
+ pry = Pry.new(output: output, target: target, commands: options[:commands])
291
+ pry.eval command_string
292
+ nil
293
+ end
294
+
295
+ def self.default_editor_for_platform
296
+ return ENV['VISUAL'] if ENV['VISUAL'] and not ENV['VISUAL'].empty?
297
+ return ENV['EDITOR'] if ENV['EDITOR'] and not ENV['EDITOR'].empty?
298
+ return 'notepad' if Helpers::Platform.windows?
299
+
300
+ %w(editor nano vi).detect do |editor|
301
+ system("which #{editor} > /dev/null 2>&1")
302
+ end
303
+ end
304
+
305
+ def self.auto_resize!
306
+ Pry.config.input # by default, load Readline
307
+
308
+ if !defined?(Readline) || Pry.config.input != Readline
309
+ warn "Sorry, you must be using Readline for Pry.auto_resize! to work."
310
+ return
311
+ end
312
+
313
+ if Readline::VERSION =~ /edit/i
314
+ warn <<-EOT
315
+ Readline version #{Readline::VERSION} detected - will not auto_resize! correctly.
316
+ For the fix, use GNU Readline instead:
317
+ https://github.com/guard/guard/wiki/Add-proper-Readline-support-to-Ruby-on-Mac-OS-X
318
+ EOT
319
+ return
320
+ end
321
+
322
+ trap :WINCH do
323
+ begin
324
+ Readline.set_screen_size(*Terminal.size!)
325
+ rescue => e
326
+ warn "\nPry.auto_resize!'s Readline.set_screen_size failed: #{e}"
327
+ end
328
+ begin
329
+ Readline.refresh_line
330
+ rescue => e
331
+ warn "\nPry.auto_resize!'s Readline.refresh_line failed: #{e}"
332
+ end
333
+ end
334
+ end
335
+
336
+ # Set all the configurable options back to their default values
337
+ def self.reset_defaults
338
+ @initial_session = true
339
+ @session_finalized = nil
340
+
341
+ self.config = Pry::Config.new Pry::Config::Default.new
342
+ self.cli = false
343
+ self.current_line = 1
344
+ self.line_buffer = [""]
345
+ self.eval_path = "(pry)"
346
+ end
347
+
348
+ # Basic initialization.
349
+ def self.init
350
+ @plugin_manager ||= PluginManager.new
351
+ reset_defaults
352
+ locate_plugins
353
+ end
354
+
355
+ # Return a `Binding` object for `target` or return `target` if it is
356
+ # already a `Binding`.
357
+ # In the case where `target` is top-level then return `TOPLEVEL_BINDING`
358
+ # @param [Object] target The object to get a `Binding` object for.
359
+ # @return [Binding] The `Binding` object.
360
+ def self.binding_for(target)
361
+ if Binding === target
362
+ target
363
+ else
364
+ if Pry.main == target
365
+ TOPLEVEL_BINDING
366
+ else
367
+ target.__binding__
368
+ end
369
+ end
370
+ end
371
+
372
+ def self.toplevel_binding
373
+ unless defined?(@toplevel_binding) && @toplevel_binding
374
+ # Grab a copy of the TOPLEVEL_BINDING without any local variables.
375
+ # This binding has a default definee of Object, and new methods are
376
+ # private (just as in TOPLEVEL_BINDING).
377
+ TOPLEVEL_BINDING.eval <<-RUBY
378
+ def self.__pry__
379
+ binding
380
+ end
381
+ Pry.toplevel_binding = __pry__
382
+ class << self; undef __pry__; end
383
+ RUBY
384
+ end
385
+ @toplevel_binding.eval('private')
386
+ @toplevel_binding
387
+ end
388
+
389
+ def self.toplevel_binding=(binding)
390
+ @toplevel_binding = binding
391
+ end
392
+
393
+ def self.in_critical_section?
394
+ Thread.current[:pry_critical_section] ||= 0
395
+ Thread.current[:pry_critical_section] > 0
396
+ end
397
+
398
+ def self.critical_section
399
+ Thread.current[:pry_critical_section] ||= 0
400
+ Thread.current[:pry_critical_section] += 1
401
+ yield
402
+ ensure
403
+ Thread.current[:pry_critical_section] -= 1
404
+ end
405
+
406
+ # Wraps a block in a named block called `Pry::Config::Lazy`. This is used for
407
+ # dynamic config values, which are calculated every time
408
+ # {Pry::Config::Lazy#call} is called.
409
+ #
410
+ # @example
411
+ # # pryrc
412
+ # Pry.config.prompt_name = Pry.lazy { rand(100) }
413
+ #
414
+ # # Session
415
+ # [1] 96(main)>
416
+ # [2] 19(main)>
417
+ # [3] 80(main)>
418
+ #
419
+ # @return [#call]
420
+ def self.lazy(&block)
421
+ Pry::Config::Lazy.new(&block)
422
+ end
423
+ end
424
+
425
+ Pry.init