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.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +21 -0
- data/README.md +26 -0
- data/chess_engine.gemspec +14 -0
- data/lib/chess_engine/board.rb +95 -0
- data/lib/chess_engine/cli.rb +105 -0
- data/lib/chess_engine/game.rb +148 -0
- data/lib/chess_engine/input.rb +19 -0
- data/lib/chess_engine/move.rb +35 -0
- data/lib/chess_engine/piece.rb +97 -0
- data/lib/chess_engine/validator.rb +87 -0
- data/lib/chess_engine.rb +1 -0
- data/spec/board_spec.rb +70 -0
- data/spec/game_helper.rb +5 -0
- data/spec/game_spec.rb +79 -0
- data/spec/spec_helper.rb +100 -0
- data/spec/validator_spec.rb +26 -0
- data/vendor/bundle/bin/coderay +27 -0
- data/vendor/bundle/bin/pry +27 -0
- data/vendor/bundle/cache/coderay-1.1.2.gem +0 -0
- data/vendor/bundle/cache/colorize-0.8.1.gem +0 -0
- data/vendor/bundle/cache/method_source-0.9.2.gem +0 -0
- data/vendor/bundle/cache/pry-0.12.2.gem +0 -0
- data/vendor/bundle/cache/rb-readline-0.5.5.gem +0 -0
- data/vendor/bundle/gems/coderay-1.1.2/MIT-LICENSE +22 -0
- data/vendor/bundle/gems/coderay-1.1.2/README_INDEX.rdoc +123 -0
- data/vendor/bundle/gems/coderay-1.1.2/bin/coderay +215 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/duo.rb +81 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/_map.rb +17 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/comment_filter.rb +25 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/count.rb +39 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug.rb +49 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug_lint.rb +63 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/div.rb +23 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/encoder.rb +190 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/filter.rb +58 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/css.rb +65 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/numbering.rb +108 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/output.rb +166 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html.rb +333 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/json.rb +83 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb +45 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lint.rb +59 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/null.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/page.rb +24 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/span.rb +23 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/statistic.rb +95 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/terminal.rb +195 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/text.rb +46 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/token_kind_filter.rb +111 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/xml.rb +72 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/yaml.rb +50 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/for_redcloth.rb +95 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/file_type.rb +151 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin.rb +55 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin_host.rb +221 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/word_list.rb +72 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/_map.rb +24 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/c.rb +189 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/clojure.rb +217 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/cpp.rb +217 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/css.rb +196 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/debug.rb +75 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/delphi.rb +144 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/diff.rb +221 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/erb.rb +81 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/go.rb +208 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/groovy.rb +268 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/haml.rb +168 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/html.rb +275 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java/builtin_types.rb +421 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java.rb +174 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java_script.rb +237 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/json.rb +98 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/lua.rb +280 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/php.rb +527 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/python.rb +287 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/raydebug.rb +75 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/patterns.rb +178 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/string_state.rb +79 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby.rb +477 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sass.rb +232 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/scanner.rb +337 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sql.rb +169 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/taskpaper.rb +36 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/text.rb +26 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/xml.rb +17 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/yaml.rb +140 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners.rb +27 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/_map.rb +7 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/alpha.rb +153 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/style.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles.rb +15 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/token_kinds.rb +85 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens.rb +161 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens_proxy.rb +55 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/version.rb +3 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay.rb +284 -0
- data/vendor/bundle/gems/colorize-0.8.1/CHANGELOG +65 -0
- data/vendor/bundle/gems/colorize-0.8.1/LICENSE +339 -0
- data/vendor/bundle/gems/colorize-0.8.1/README.md +105 -0
- data/vendor/bundle/gems/colorize-0.8.1/Rakefile +13 -0
- data/vendor/bundle/gems/colorize-0.8.1/colorize.gemspec +36 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/class_methods.rb +120 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/instance_methods.rb +132 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize.rb +12 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorized_string.rb +19 -0
- data/vendor/bundle/gems/colorize-0.8.1/test/test_colorize.rb +164 -0
- data/vendor/bundle/gems/method_source-0.9.2/Gemfile +2 -0
- data/vendor/bundle/gems/method_source-0.9.2/LICENSE +25 -0
- data/vendor/bundle/gems/method_source-0.9.2/README.markdown +91 -0
- data/vendor/bundle/gems/method_source-0.9.2/Rakefile +81 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/code_helpers.rb +154 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/source_location.rb +138 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/version.rb +3 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source.rb +141 -0
- data/vendor/bundle/gems/method_source-0.9.2/method_source.gemspec +35 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/method_source/code_helpers_spec.rb +43 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/method_source_spec.rb +143 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/spec_helper.rb +101 -0
- data/vendor/bundle/gems/pry-0.12.2/CHANGELOG.md +953 -0
- data/vendor/bundle/gems/pry-0.12.2/LICENSE +25 -0
- data/vendor/bundle/gems/pry-0.12.2/README.md +390 -0
- data/vendor/bundle/gems/pry-0.12.2/bin/pry +8 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/basic_object.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/cli.rb +218 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_file.rb +110 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_range.rb +71 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/loc.rb +98 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code.rb +353 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code_object.rb +195 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/color_printer.rb +65 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/command.rb +723 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/command_set.rb +415 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/amend_line.rb +98 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang.rb +20 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang_pry.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/exception_formatter.rb +79 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/file_formatter.rb +71 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat.rb +63 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cd.rb +41 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_inspector.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/clear_screen.rb +14 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/code_collector.rb +167 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disable_pry.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disabled_commands.rb +2 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/easter_eggs.rb +112 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit.rb +200 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit.rb +43 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_all.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_program.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/find_method.rb +191 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/fix_indent.rb +19 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_cd.rb +26 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_install.rb +32 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_list.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_open.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_readme.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_search.rb +40 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_stats.rb +83 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gist.rb +102 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/help.rb +164 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/hist.rb +181 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/import_set.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/install_command.rb +54 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/jump_to.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/list_inspectors.rb +35 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/constants.rb +58 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/formatter.rb +51 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/globals.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/grep.rb +19 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/instance_vars.rb +38 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_names.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_vars.rb +37 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/ls_entity.rb +69 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods.rb +54 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/self_methods.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls.rb +113 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/nesting.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/play.rb +102 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_backtrace.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_version.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/raise_up.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reload_code.rb +62 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reset.rb +18 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ri.rb +65 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/save_file.rb +61 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_command.rb +75 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_mode.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_doc.rb +81 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_info.rb +216 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_input.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_source.rb +53 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/stat.rb +40 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/switch_to.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/toggle_color.rb +24 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression.rb +107 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/whereami.rb +197 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/wtf.rb +70 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/behavior.rb +255 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/convenience.rb +28 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/default.rb +159 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/memoization.rb +48 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config.rb +35 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/core_extensions.rb +142 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/editor.rb +128 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/exceptions.rb +76 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/forwardable.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/base_helpers.rb +200 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/command_helpers.rb +157 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/documentation_helpers.rb +76 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/options_helpers.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/platform.rb +58 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/table.rb +114 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/text.rb +115 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/history.rb +161 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/hooks.rb +171 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/indent.rb +408 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_completer.rb +265 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_lock.rb +130 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/inspector.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/last_exception.rb +61 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/disowned.rb +55 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/patcher.rb +122 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/weird_method_locator.rb +198 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method.rb +552 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/object_path.rb +83 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/output.rb +50 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pager.rb +250 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/platform.rb +91 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/plugins.rb +122 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/prompt.rb +145 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_class.rb +425 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_instance.rb +699 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl.rb +261 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl_file_loader.rb +73 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/ring.rb +84 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/rubygem.rb +84 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/LICENSE +20 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/commands.rb +195 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/option.rb +206 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop.rb +661 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/terminal.rb +91 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/evalable.rb +15 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/mockable.rb +14 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/pry_tester.rb +73 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/utility.rb +26 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/variables.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable.rb +70 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/version.rb +3 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module/candidate.rb +131 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module.rb +378 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry.rb +132 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/CHANGES +94 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/LICENSE +25 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/README.md +81 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/Rakefile +25 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/bench/_rl_adjust_point.rb +26 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline.rb +8 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline_with_completion.rb +18 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/tinyirb.rb +11 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rb-readline.rb +18 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline/version.rb +3 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline.rb +8920 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/readline.rb +539 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/rb-readline.gemspec +51 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/setup.rb +1585 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/support/filesystem_completion_helper.rb +53 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_completion.rb +100 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_filename_completion_proc.rb +88 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_history.rb +29 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_rbreadline.rb +23 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_readline.rb +221 -0
- data/vendor/bundle/specifications/coderay-1.1.2.gemspec +26 -0
- data/vendor/bundle/specifications/colorize-0.8.1.gemspec +38 -0
- data/vendor/bundle/specifications/method_source-0.9.2.gemspec +35 -0
- data/vendor/bundle/specifications/pry-0.12.2.gemspec +38 -0
- data/vendor/bundle/specifications/rb-readline-0.5.5.gemspec +39 -0
- metadata +363 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
class Pry
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
# This class contains methods useful for extracting
|
5
|
+
# documentation from methods and classes.
|
6
|
+
module DocumentationHelpers
|
7
|
+
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def process_rdoc(comment)
|
11
|
+
comment = comment.dup
|
12
|
+
comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { CodeRay.scan($1, :ruby).term }.
|
13
|
+
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { "\e[1m#{$1}\e[0m" }.
|
14
|
+
gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { "\e[1m#{$1}\e[0m" }.
|
15
|
+
gsub(/<tt>(?:\s*\n)?(.*?)\s*<\/tt>/m) { CodeRay.scan($1, :ruby).term }.
|
16
|
+
gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{$1}\e[0m" }.
|
17
|
+
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { CodeRay.scan($1, :ruby).term }.
|
18
|
+
gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{CodeRay.scan($1, :ruby).term}`" }
|
19
|
+
end
|
20
|
+
|
21
|
+
def process_yardoc_tag(comment, tag)
|
22
|
+
in_tag_block = nil
|
23
|
+
comment.lines.map do |v|
|
24
|
+
if in_tag_block && v !~ /^\S/
|
25
|
+
Pry::Helpers::Text.strip_color Pry::Helpers::Text.strip_color(v)
|
26
|
+
elsif in_tag_block
|
27
|
+
in_tag_block = false
|
28
|
+
v
|
29
|
+
else
|
30
|
+
in_tag_block = true if v =~ /^@#{tag}/
|
31
|
+
v
|
32
|
+
end
|
33
|
+
end.join
|
34
|
+
end
|
35
|
+
|
36
|
+
def process_yardoc(comment)
|
37
|
+
yard_tags = ["param", "return", "option", "yield", "attr", "attr_reader", "attr_writer",
|
38
|
+
"deprecate", "example", "raise"]
|
39
|
+
(yard_tags - ["example"]).inject(comment) { |a, v| process_yardoc_tag(a, v) }.
|
40
|
+
gsub(/^@(#{yard_tags.join("|")})/) { "\e[33m#{$1}\e[0m" }
|
41
|
+
end
|
42
|
+
|
43
|
+
def process_comment_markup(comment)
|
44
|
+
process_yardoc process_rdoc(comment)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @param [String] code
|
48
|
+
# @return [String]
|
49
|
+
def strip_comments_from_c_code(code)
|
50
|
+
code.sub(/\A\s*\/\*.*?\*\/\s*/m, '')
|
51
|
+
end
|
52
|
+
|
53
|
+
# Given a string that makes up a comment in a source-code file parse out the content
|
54
|
+
# that the user is intended to read. (i.e. without leading indentation, #-characters
|
55
|
+
# or shebangs)
|
56
|
+
#
|
57
|
+
# @param [String] comment
|
58
|
+
# @return [String]
|
59
|
+
def get_comment_content(comment)
|
60
|
+
comment = comment.dup
|
61
|
+
# Remove #!/usr/bin/ruby
|
62
|
+
comment.gsub!(/\A\#!.*$/, '')
|
63
|
+
# Remove leading empty comment lines
|
64
|
+
comment.gsub!(/\A\#+?$/, '')
|
65
|
+
comment.gsub!(/^\s*#/, '')
|
66
|
+
strip_leading_whitespace(comment)
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param [String] text
|
70
|
+
# @return [String]
|
71
|
+
def strip_leading_whitespace(text)
|
72
|
+
Pry::Helpers::CommandHelpers.unindent(text)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Pry
|
2
|
+
module Helpers
|
3
|
+
module OptionsHelpers
|
4
|
+
module_function
|
5
|
+
|
6
|
+
# Add method options to the Pry::Slop instance
|
7
|
+
def method_options(opt)
|
8
|
+
@method_target = target
|
9
|
+
opt.on :M, "instance-methods", "Operate on instance methods."
|
10
|
+
opt.on :m, :methods, "Operate on methods."
|
11
|
+
opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors.", as: :count
|
12
|
+
opt.on :c, :context, "Select object context to run under.", argument: true do |context|
|
13
|
+
@method_target = Pry.binding_for(target.eval(context))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Get the method object parsed by the slop instance
|
18
|
+
def method_object
|
19
|
+
@method_object ||= get_method_or_raise(args.empty? ? nil : args.join(" "), @method_target,
|
20
|
+
super: opts[:super],
|
21
|
+
instance: opts.present?(:'instance-methods') && !opts.present?(:'methods'),
|
22
|
+
methods: opts.present?(:'methods') && !opts.present?(:'instance-methods')
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class Pry
|
2
|
+
module Helpers
|
3
|
+
# Contains methods for querying the platform that Pry is running on
|
4
|
+
# @api public
|
5
|
+
# @since v0.12.0
|
6
|
+
# rubocop:disable Style/DoubleNegation
|
7
|
+
module Platform
|
8
|
+
# @return [Boolean]
|
9
|
+
def self.mac_osx?
|
10
|
+
!!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i)
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [Boolean]
|
14
|
+
def self.linux?
|
15
|
+
!!(RbConfig::CONFIG['host_os'] =~ /linux/i)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Boolean] true when Pry is running on Windows with ANSI support,
|
19
|
+
# false otherwise
|
20
|
+
def self.windows?
|
21
|
+
!!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Boolean]
|
25
|
+
def self.windows_ansi?
|
26
|
+
return false unless windows?
|
27
|
+
|
28
|
+
!!(defined?(Win32::Console) || ENV['ANSICON'] || mri_2?)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Boolean]
|
32
|
+
def self.jruby?
|
33
|
+
RbConfig::CONFIG['ruby_install_name'] == 'jruby'
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Boolean]
|
37
|
+
def self.jruby_19?
|
38
|
+
jruby? && RbConfig::CONFIG['ruby_version'] == '1.9'
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [Boolean]
|
42
|
+
def self.mri?
|
43
|
+
RbConfig::CONFIG['ruby_install_name'] == 'ruby'
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Boolean]
|
47
|
+
def self.mri_19?
|
48
|
+
!!(mri? && RUBY_VERSION.start_with?('1.9'))
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Boolean]
|
52
|
+
def self.mri_2?
|
53
|
+
!!(mri? && RUBY_VERSION.start_with?('2'))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
# rubocop:enable Style/DoubleNegation
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
class Pry
|
2
|
+
module Helpers
|
3
|
+
def self.tablify_or_one_line(heading, things, config = Pry.config)
|
4
|
+
plain_heading = Pry::Helpers::Text.strip_color(heading)
|
5
|
+
attempt = Table.new(things, column_count: things.size)
|
6
|
+
if attempt.fits_on_line?(Terminal.width! - plain_heading.size - 2)
|
7
|
+
"#{heading}: #{attempt}\n"
|
8
|
+
else
|
9
|
+
"#{heading}: \n#{tablify_to_screen_width(things, { indent: ' ' }, config)}\n"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.tablify_to_screen_width(things, options, config = Pry.config)
|
14
|
+
options ||= {}
|
15
|
+
things = things.compact
|
16
|
+
if (indent = options[:indent])
|
17
|
+
usable_width = Terminal.width! - indent.size
|
18
|
+
tablify(things, usable_width, config).to_s.gsub(/^/, indent)
|
19
|
+
else
|
20
|
+
tablify(things, Terminal.width!, config).to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.tablify(things, line_length, config = Pry.config)
|
25
|
+
table = Table.new(things, { column_count: things.size }, config)
|
26
|
+
table.column_count -= 1 until 1 == table.column_count or
|
27
|
+
table.fits_on_line?(line_length)
|
28
|
+
table
|
29
|
+
end
|
30
|
+
|
31
|
+
class Table
|
32
|
+
attr_reader :items, :column_count
|
33
|
+
def initialize(items, args, config = Pry.config)
|
34
|
+
@column_count = args[:column_count]
|
35
|
+
@config = config
|
36
|
+
self.items = items
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
rows_to_s.join("\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
def rows_to_s style = :color_on
|
44
|
+
widths = columns.map { |e| _max_width(e) }
|
45
|
+
@rows_without_colors.map do |r|
|
46
|
+
padded = []
|
47
|
+
r.each_with_index do |e,i|
|
48
|
+
next unless e
|
49
|
+
|
50
|
+
item = e.ljust(widths[i])
|
51
|
+
item.sub! e, _recall_color_for(e) if :color_on == style
|
52
|
+
padded << item
|
53
|
+
end
|
54
|
+
padded.join(@config.ls.separator)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def items= items
|
59
|
+
@items = items
|
60
|
+
_rebuild_colorless_cache
|
61
|
+
_recolumn
|
62
|
+
items
|
63
|
+
end
|
64
|
+
|
65
|
+
def column_count= n
|
66
|
+
@column_count = n
|
67
|
+
_recolumn
|
68
|
+
end
|
69
|
+
|
70
|
+
def fits_on_line? line_length
|
71
|
+
_max_width(rows_to_s :no_color) <= line_length
|
72
|
+
end
|
73
|
+
|
74
|
+
def columns
|
75
|
+
@rows_without_colors.transpose
|
76
|
+
end
|
77
|
+
|
78
|
+
def ==(other); items == other.to_a end
|
79
|
+
|
80
|
+
def to_a; items.to_a end
|
81
|
+
|
82
|
+
private
|
83
|
+
def _max_width(things)
|
84
|
+
things.compact.map(&:size).max || 0
|
85
|
+
end
|
86
|
+
|
87
|
+
def _rebuild_colorless_cache
|
88
|
+
@colorless_cache = {}
|
89
|
+
@plain_items = []
|
90
|
+
items.map do |e|
|
91
|
+
plain = Pry::Helpers::Text.strip_color(e)
|
92
|
+
@colorless_cache[plain] = e
|
93
|
+
@plain_items << plain
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def _recolumn
|
98
|
+
@rows_without_colors = []
|
99
|
+
return if items.size.zero?
|
100
|
+
|
101
|
+
row_count = (items.size.to_f / column_count).ceil
|
102
|
+
row_count.times do |i|
|
103
|
+
row_indices = (0...column_count).map { |e| row_count * e + i }
|
104
|
+
@rows_without_colors << row_indices.map { |e| @plain_items[e] }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def _recall_color_for thing
|
109
|
+
@colorless_cache[thing]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
class Pry
|
2
|
+
module Helpers
|
3
|
+
# The methods defined on {Text} are available to custom commands via {Pry::Command#text}.
|
4
|
+
module Text
|
5
|
+
extend self
|
6
|
+
COLORS =
|
7
|
+
{
|
8
|
+
"black" => 0,
|
9
|
+
"red" => 1,
|
10
|
+
"green" => 2,
|
11
|
+
"yellow" => 3,
|
12
|
+
"blue" => 4,
|
13
|
+
"purple" => 5,
|
14
|
+
"magenta" => 5,
|
15
|
+
"cyan" => 6,
|
16
|
+
"white" => 7
|
17
|
+
}
|
18
|
+
|
19
|
+
COLORS.each_pair do |color, value|
|
20
|
+
define_method color do |text|
|
21
|
+
"\033[0;#{30 + value}m#{text}\033[0m"
|
22
|
+
end
|
23
|
+
|
24
|
+
define_method "bright_#{color}" do |text|
|
25
|
+
"\033[1;#{30 + value}m#{text}\033[0m"
|
26
|
+
end
|
27
|
+
|
28
|
+
COLORS.each_pair do |bg_color, bg_value|
|
29
|
+
define_method "#{color}_on_#{bg_color}" do |text|
|
30
|
+
"\033[0;#{30 + value};#{40 + bg_value}m#{text}\033[0m"
|
31
|
+
end
|
32
|
+
|
33
|
+
define_method "bright_#{color}_on_#{bg_color}" do |text|
|
34
|
+
"\033[1;#{30 + value};#{40 + bg_value}m#{text}\033[0m"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Remove any color codes from _text_.
|
40
|
+
#
|
41
|
+
# @param [String, #to_s] text
|
42
|
+
# @return [String] _text_ stripped of any color codes.
|
43
|
+
def strip_color(text)
|
44
|
+
text.to_s.gsub(/(\001)?\e\[.*?(\d)+m(\002)?/ , '')
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns _text_ as bold text for use on a terminal.
|
48
|
+
#
|
49
|
+
# @param [String, #to_s] text
|
50
|
+
# @return [String] _text_
|
51
|
+
def bold(text)
|
52
|
+
"\e[1m#{text}\e[0m"
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns `text` in the default foreground colour.
|
56
|
+
# Use this instead of "black" or "white" when you mean absence of colour.
|
57
|
+
#
|
58
|
+
# @param [String, #to_s] text
|
59
|
+
# @return [String]
|
60
|
+
def default(text)
|
61
|
+
text.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# @yield
|
66
|
+
# Yields a block with color turned off.
|
67
|
+
#
|
68
|
+
# @return [void]
|
69
|
+
#
|
70
|
+
def no_color
|
71
|
+
boolean = Pry.config.color
|
72
|
+
Pry.config.color = false
|
73
|
+
yield
|
74
|
+
ensure
|
75
|
+
Pry.config.color = boolean
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# @yield
|
80
|
+
# Yields a block with paging turned off.
|
81
|
+
#
|
82
|
+
# @return [void]
|
83
|
+
#
|
84
|
+
def no_pager
|
85
|
+
boolean = Pry.config.pager
|
86
|
+
Pry.config.pager = false
|
87
|
+
yield
|
88
|
+
ensure
|
89
|
+
Pry.config.pager = boolean
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns _text_ in a numbered list, beginning at _offset_.
|
93
|
+
#
|
94
|
+
# @param [#each_line] text
|
95
|
+
# @param [Fixnum] offset
|
96
|
+
# @return [String]
|
97
|
+
def with_line_numbers(text, offset, color = :blue)
|
98
|
+
lines = text.each_line.to_a
|
99
|
+
max_width = (offset + lines.count).to_s.length
|
100
|
+
lines.each_with_index.map do |line, index|
|
101
|
+
adjusted_index = (index + offset).to_s.rjust(max_width)
|
102
|
+
"#{self.send(color, adjusted_index)}: #{line}"
|
103
|
+
end.join
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns _text_ indented by _chars_ spaces.
|
107
|
+
#
|
108
|
+
# @param [String] text
|
109
|
+
# @param [Fixnum] chars
|
110
|
+
def indent(text, chars)
|
111
|
+
text.lines.map { |l| "#{' ' * chars}#{l}" }.join
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
class Pry
|
2
|
+
# The History class is responsible for maintaining the user's input history,
|
3
|
+
# both internally and within Readline.
|
4
|
+
class History
|
5
|
+
attr_accessor :loader, :saver, :pusher, :clearer
|
6
|
+
|
7
|
+
# @return [Fixnum] Number of lines in history when Pry first loaded.
|
8
|
+
attr_reader :original_lines
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@history = []
|
12
|
+
@original_lines = 0
|
13
|
+
@file_path = options[:file_path]
|
14
|
+
restore_default_behavior
|
15
|
+
end
|
16
|
+
|
17
|
+
# Assign the default methods for loading, saving, pushing, and clearing.
|
18
|
+
def restore_default_behavior
|
19
|
+
Pry.config.input # force Readline to load if applicable
|
20
|
+
|
21
|
+
@loader = method(:read_from_file)
|
22
|
+
@saver = method(:save_to_file)
|
23
|
+
|
24
|
+
if defined?(Readline)
|
25
|
+
@pusher = method(:push_to_readline)
|
26
|
+
@clearer = method(:clear_readline)
|
27
|
+
else
|
28
|
+
@pusher = proc {}
|
29
|
+
@clearer = proc {}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Load the input history using `History.loader`.
|
34
|
+
# @return [Integer] The number of lines loaded
|
35
|
+
def load
|
36
|
+
@loader.call do |line|
|
37
|
+
next if invalid_readline_line?(line)
|
38
|
+
|
39
|
+
@pusher.call(line.chomp)
|
40
|
+
@history << line.chomp
|
41
|
+
@original_lines += 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Add a line to the input history, ignoring blank and duplicate lines.
|
46
|
+
# @param [String] line
|
47
|
+
# @return [String] The same line that was passed in
|
48
|
+
def push(line)
|
49
|
+
empty_or_invalid_line = line.empty? || invalid_readline_line?(line)
|
50
|
+
|
51
|
+
unless empty_or_invalid_line || (@history.last && line == @history.last)
|
52
|
+
@pusher.call(line)
|
53
|
+
@history << line
|
54
|
+
if !should_ignore?(line) && Pry.config.history.should_save
|
55
|
+
@saver.call(line)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
line
|
59
|
+
end
|
60
|
+
alias << push
|
61
|
+
|
62
|
+
# Clear this session's history. This won't affect the contents of the
|
63
|
+
# history file.
|
64
|
+
def clear
|
65
|
+
@clearer.call
|
66
|
+
@original_lines = 0
|
67
|
+
@history = []
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [Fixnum] The number of lines in history.
|
71
|
+
def history_line_count
|
72
|
+
@history.count
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [Fixnum] The number of lines in history from just this session.
|
76
|
+
def session_line_count
|
77
|
+
@history.count - @original_lines
|
78
|
+
end
|
79
|
+
|
80
|
+
# Return an Array containing all stored history.
|
81
|
+
# @return [Array<String>] An Array containing all lines of history loaded
|
82
|
+
# or entered by the user in the current session.
|
83
|
+
def to_a
|
84
|
+
@history.dup
|
85
|
+
end
|
86
|
+
|
87
|
+
# Filter the history with the histignore options
|
88
|
+
# @return [Array<String>] An array containing all the lines that are not
|
89
|
+
# included in the histignore.
|
90
|
+
def filter(history)
|
91
|
+
history.select { |l| l unless should_ignore?(l) }
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
# Check if the line match any option in the histignore
|
97
|
+
# [Pry.config.history.histignore]
|
98
|
+
# @return [Boolean] a boolean that notifies if the line was found in the
|
99
|
+
# histignore array.
|
100
|
+
def should_ignore?(line)
|
101
|
+
hist_ignore = Pry.config.history.histignore
|
102
|
+
return false if hist_ignore.nil? || hist_ignore.empty?
|
103
|
+
|
104
|
+
hist_ignore.any? { |p| line.to_s.match(p) }
|
105
|
+
end
|
106
|
+
|
107
|
+
# The default loader. Yields lines from `Pry.history.config.file`.
|
108
|
+
def read_from_file
|
109
|
+
path = history_file_path
|
110
|
+
|
111
|
+
if File.exist?(path)
|
112
|
+
File.foreach(path) { |line| yield(line) }
|
113
|
+
end
|
114
|
+
rescue SystemCallError => error
|
115
|
+
warn "Unable to read history file: #{error.message}"
|
116
|
+
end
|
117
|
+
|
118
|
+
# The default pusher. Appends the given line to Readline::HISTORY.
|
119
|
+
# @param [String] line
|
120
|
+
def push_to_readline(line)
|
121
|
+
Readline::HISTORY << line
|
122
|
+
end
|
123
|
+
|
124
|
+
# The default clearer. Clears Readline::HISTORY.
|
125
|
+
def clear_readline
|
126
|
+
Readline::HISTORY.shift until Readline::HISTORY.empty?
|
127
|
+
end
|
128
|
+
|
129
|
+
# The default saver. Appends the given line to `Pry.history.config.file`.
|
130
|
+
def save_to_file(line)
|
131
|
+
history_file.puts line if history_file
|
132
|
+
end
|
133
|
+
|
134
|
+
# The history file, opened for appending.
|
135
|
+
def history_file
|
136
|
+
if defined?(@history_file)
|
137
|
+
@history_file
|
138
|
+
else
|
139
|
+
unless File.exist?(history_file_path)
|
140
|
+
FileUtils.mkdir_p(File.dirname(history_file_path))
|
141
|
+
end
|
142
|
+
@history_file = File.open(history_file_path, 'a', 0600).tap do |file|
|
143
|
+
file.sync = true
|
144
|
+
end
|
145
|
+
end
|
146
|
+
rescue SystemCallError => error
|
147
|
+
warn "Unable to write history file: #{error.message}"
|
148
|
+
@history_file = false
|
149
|
+
end
|
150
|
+
|
151
|
+
def history_file_path
|
152
|
+
File.expand_path(@file_path || Pry.config.history.file)
|
153
|
+
end
|
154
|
+
|
155
|
+
def invalid_readline_line?(line)
|
156
|
+
# `Readline::HISTORY << line` raises an `ArgumentError` if `line`
|
157
|
+
# includes a null byte
|
158
|
+
line.include?("\0")
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|