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,110 @@
|
|
1
|
+
class Pry
|
2
|
+
class CodeFile
|
3
|
+
DEFAULT_EXT = '.rb'
|
4
|
+
|
5
|
+
# List of all supported languages.
|
6
|
+
# @return [Hash]
|
7
|
+
EXTENSIONS = {
|
8
|
+
%w(.py) => :python,
|
9
|
+
%w(.js) => :javascript,
|
10
|
+
%w(.css) => :css,
|
11
|
+
%w(.xml) => :xml,
|
12
|
+
%w(.php) => :php,
|
13
|
+
%w(.html) => :html,
|
14
|
+
%w(.diff) => :diff,
|
15
|
+
%w(.java) => :java,
|
16
|
+
%w(.json) => :json,
|
17
|
+
%w(.c .h) => :c,
|
18
|
+
%w(.rhtml) => :rhtml,
|
19
|
+
%w(.yaml .yml) => :yaml,
|
20
|
+
%w(.cpp .hpp .cc .h .cxx) => :cpp,
|
21
|
+
%w(.rb .ru .irbrc .gemspec .pryrc .rake) => :ruby,
|
22
|
+
}
|
23
|
+
|
24
|
+
FILES = {
|
25
|
+
%w(Gemfile Rakefile Guardfile Capfile) => :ruby
|
26
|
+
}
|
27
|
+
|
28
|
+
# Store the current working directory. This allows show-source etc. to work if
|
29
|
+
# your process has changed directory since boot. [Issue #675]
|
30
|
+
INITIAL_PWD = Dir.pwd
|
31
|
+
|
32
|
+
# @return [Symbol] The type of code stored in this wrapper.
|
33
|
+
attr_reader :code_type
|
34
|
+
|
35
|
+
# @param [String] filename The name of a file with code to be detected
|
36
|
+
# @param [Symbol] code_type The type of code the `filename` contains
|
37
|
+
def initialize(filename, code_type = type_from_filename(filename))
|
38
|
+
@filename = filename
|
39
|
+
@code_type = code_type
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [String] The code contained in the current `@filename`.
|
43
|
+
def code
|
44
|
+
if @filename == Pry.eval_path
|
45
|
+
Pry.line_buffer.drop(1)
|
46
|
+
elsif Pry::Method::Patcher.code_for(@filename)
|
47
|
+
Pry::Method::Patcher.code_for(@filename)
|
48
|
+
else
|
49
|
+
path = abs_path
|
50
|
+
@code_type = type_from_filename(path)
|
51
|
+
File.read(path)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
# @raise [MethodSource::SourceNotFoundError] if the `filename` is not
|
58
|
+
# readable for some reason.
|
59
|
+
# @return [String] absolute path for the given `filename`.
|
60
|
+
def abs_path
|
61
|
+
code_path.detect { |path| readable?(path) } or
|
62
|
+
raise MethodSource::SourceNotFoundError,
|
63
|
+
"Cannot open #{ @filename.inspect } for reading."
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param [String] path
|
67
|
+
# @return [Boolean] if the path, with or without the default ext,
|
68
|
+
# is a readable file then `true`, otherwise `false`.
|
69
|
+
def readable?(path)
|
70
|
+
File.readable?(path) && !File.directory?(path) or
|
71
|
+
File.readable?(path << DEFAULT_EXT)
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [Array] All the paths that contain code that Pry can use for its
|
75
|
+
# API's. Skips directories.
|
76
|
+
def code_path
|
77
|
+
[from_pwd, from_pry_init_pwd, *from_load_path]
|
78
|
+
end
|
79
|
+
|
80
|
+
# @param [String] filename
|
81
|
+
# @param [Symbol] default (:unknown) the file type to assume if none could be
|
82
|
+
# detected.
|
83
|
+
# @return [Symbol, nil] The CodeRay type of a file from its extension, or
|
84
|
+
# `nil` if `:unknown`.
|
85
|
+
def type_from_filename(filename, default = :unknown)
|
86
|
+
_, @code_type = EXTENSIONS.find do |k, _|
|
87
|
+
k.any? { |ext| ext == File.extname(filename) }
|
88
|
+
end || FILES.find do |k, _|
|
89
|
+
k.any? { |file_name| file_name == File.basename(filename) }
|
90
|
+
end
|
91
|
+
|
92
|
+
code_type || default
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return [String]
|
96
|
+
def from_pwd
|
97
|
+
File.expand_path(@filename, Dir.pwd)
|
98
|
+
end
|
99
|
+
|
100
|
+
# @return [String]
|
101
|
+
def from_pry_init_pwd
|
102
|
+
File.expand_path(@filename, INITIAL_PWD)
|
103
|
+
end
|
104
|
+
|
105
|
+
# @return [String]
|
106
|
+
def from_load_path
|
107
|
+
$LOAD_PATH.map { |path| File.expand_path(@filename, path) }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class Pry
|
2
|
+
class Code
|
3
|
+
# Represents a range of lines in a code listing.
|
4
|
+
#
|
5
|
+
# @api private
|
6
|
+
class CodeRange
|
7
|
+
# @param [Integer] start_line
|
8
|
+
# @param [Integer?] end_line
|
9
|
+
def initialize(start_line, end_line = nil)
|
10
|
+
@start_line = start_line
|
11
|
+
@end_line = end_line
|
12
|
+
force_set_end_line
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param [Array<LOC>] lines
|
16
|
+
# @return [Range]
|
17
|
+
def indices_range(lines)
|
18
|
+
Range.new(*indices(lines))
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def start_line; @start_line; end
|
24
|
+
|
25
|
+
def end_line; @end_line; end
|
26
|
+
|
27
|
+
# If `end_line` is equal to `nil`, then calculate it from the first
|
28
|
+
# parameter, `start_line`. Otherwise, leave it as it is.
|
29
|
+
# @return [void]
|
30
|
+
def force_set_end_line
|
31
|
+
if start_line.is_a?(Range)
|
32
|
+
set_end_line_from_range
|
33
|
+
else
|
34
|
+
@end_line ||= start_line
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Finds indices of `start_line` and `end_line` in the given Array of
|
39
|
+
# +lines+.
|
40
|
+
#
|
41
|
+
# @param [Array<LOC>] lines
|
42
|
+
# @return [Array<Integer>]
|
43
|
+
def indices(lines)
|
44
|
+
[find_start_index(lines), find_end_index(lines)]
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Integer]
|
48
|
+
def find_start_index(lines)
|
49
|
+
return start_line if start_line < 0
|
50
|
+
|
51
|
+
lines.index { |loc| loc.lineno >= start_line } || lines.length
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Integer]
|
55
|
+
def find_end_index(lines)
|
56
|
+
return end_line if end_line < 0
|
57
|
+
|
58
|
+
(lines.index { |loc| loc.lineno > end_line } || 0) - 1
|
59
|
+
end
|
60
|
+
|
61
|
+
# For example, if the range is 4..10, then `start_line` would be equal to
|
62
|
+
# 4 and `end_line` to 10.
|
63
|
+
# @return [void]
|
64
|
+
def set_end_line_from_range
|
65
|
+
@end_line = start_line.last
|
66
|
+
@end_line -= 1 if start_line.exclude_end?
|
67
|
+
@start_line = start_line.first
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class Pry
|
2
|
+
class Code
|
3
|
+
# Represents a line of code (which may, in fact, contain multiple lines if the
|
4
|
+
# entirety was eval'd as a single unit following the `edit` command).
|
5
|
+
#
|
6
|
+
# A line of code is a tuple, which consists of a line and a line number. A
|
7
|
+
# `LOC` object's state (namely, the line parameter) can be changed via
|
8
|
+
# instance methods. `Pry::Code` heavily uses this class.
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
# @example
|
12
|
+
# loc = LOC.new("def example\n :example\nend", 1)
|
13
|
+
# puts loc.line
|
14
|
+
# def example
|
15
|
+
# :example
|
16
|
+
# end
|
17
|
+
# #=> nil
|
18
|
+
#
|
19
|
+
# loc.indent(3)
|
20
|
+
# loc.line #=> " def example\n :example\nend"
|
21
|
+
class LOC
|
22
|
+
# @return [Array<String, Integer>]
|
23
|
+
attr_reader :tuple
|
24
|
+
|
25
|
+
# @param [String] line The line of code.
|
26
|
+
# @param [Integer] lineno The position of the +line+.
|
27
|
+
def initialize(line, lineno)
|
28
|
+
@tuple = [line.chomp, lineno.to_i]
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Boolean]
|
32
|
+
def ==(other)
|
33
|
+
other.tuple == tuple
|
34
|
+
end
|
35
|
+
|
36
|
+
def dup
|
37
|
+
self.class.new(line, lineno)
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [String]
|
41
|
+
def line
|
42
|
+
tuple.first
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Integer]
|
46
|
+
def lineno
|
47
|
+
tuple.last
|
48
|
+
end
|
49
|
+
|
50
|
+
# Paints the `line` of code.
|
51
|
+
#
|
52
|
+
# @param [Symbol] code_type
|
53
|
+
# @return [void]
|
54
|
+
def colorize(code_type)
|
55
|
+
tuple[0] = CodeRay.scan(line, code_type).term
|
56
|
+
end
|
57
|
+
|
58
|
+
# Prepends the line number `lineno` to the `line`.
|
59
|
+
#
|
60
|
+
# @param [Integer] max_width
|
61
|
+
# @return [void]
|
62
|
+
def add_line_number(max_width = 0, color = false)
|
63
|
+
padded = lineno.to_s.rjust(max_width)
|
64
|
+
colorized_lineno = color ? Pry::Helpers::BaseHelpers.colorize_code(padded) : padded
|
65
|
+
properly_padded_line = handle_multiline_entries_from_edit_command(line, max_width)
|
66
|
+
tuple[0] = "#{ colorized_lineno }: #{ properly_padded_line }"
|
67
|
+
end
|
68
|
+
|
69
|
+
# Prepends a marker "=>" or an empty marker to the +line+.
|
70
|
+
#
|
71
|
+
# @param [Integer] marker_lineno If it is equal to the `lineno`, then
|
72
|
+
# prepend a hashrocket. Otherwise, an empty marker.
|
73
|
+
# @return [void]
|
74
|
+
def add_marker(marker_lineno)
|
75
|
+
tuple[0] =
|
76
|
+
if lineno == marker_lineno
|
77
|
+
" => #{ line }"
|
78
|
+
else
|
79
|
+
" #{ line }"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Indents the `line` with +distance+ spaces.
|
84
|
+
#
|
85
|
+
# @param [Integer] distance
|
86
|
+
# @return [void]
|
87
|
+
def indent(distance)
|
88
|
+
tuple[0] = "#{ ' ' * distance }#{ line }"
|
89
|
+
end
|
90
|
+
|
91
|
+
def handle_multiline_entries_from_edit_command(line, max_width)
|
92
|
+
line.split("\n").map.with_index do |inner_line, i|
|
93
|
+
i.zero? ? inner_line : "#{' ' * (max_width + 2)}#{inner_line}"
|
94
|
+
end.join("\n")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,353 @@
|
|
1
|
+
require 'pry/code/loc'
|
2
|
+
require 'pry/code/code_range'
|
3
|
+
require 'pry/code/code_file'
|
4
|
+
|
5
|
+
class Pry
|
6
|
+
class << self
|
7
|
+
# Convert the given object into an instance of `Pry::Code`, if it isn't
|
8
|
+
# already one.
|
9
|
+
#
|
10
|
+
# @param [Code, Method, UnboundMethod, Proc, Pry::Method, String, Array,
|
11
|
+
# IO] obj
|
12
|
+
def Code(obj)
|
13
|
+
case obj
|
14
|
+
when Code
|
15
|
+
obj
|
16
|
+
when ::Method, UnboundMethod, Proc, Pry::Method
|
17
|
+
Code.from_method(obj)
|
18
|
+
else
|
19
|
+
Code.new(obj)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# `Pry::Code` is a class that encapsulates lines of source code and their
|
25
|
+
# line numbers and formats them for terminal output. It can read from a file
|
26
|
+
# or method definition or be instantiated with a `String` or an `Array`.
|
27
|
+
#
|
28
|
+
# In general, the formatting methods in `Code` return a new `Code` object
|
29
|
+
# which will format the text as specified when `#to_s` is called. This allows
|
30
|
+
# arbitrary chaining of formatting methods without mutating the original
|
31
|
+
# object.
|
32
|
+
class Code
|
33
|
+
class << self
|
34
|
+
include MethodSource::CodeHelpers
|
35
|
+
|
36
|
+
# Instantiate a `Code` object containing code loaded from a file or
|
37
|
+
# Pry's line buffer.
|
38
|
+
#
|
39
|
+
# @param [String] filename The name of a file, or "(pry)".
|
40
|
+
# @param [Symbol] code_type The type of code the file contains.
|
41
|
+
# @return [Code]
|
42
|
+
def from_file(filename, code_type = nil)
|
43
|
+
code_file = CodeFile.new(filename, code_type)
|
44
|
+
new(code_file.code, 1, code_file.code_type)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Instantiate a `Code` object containing code extracted from a
|
48
|
+
# `::Method`, `UnboundMethod`, `Proc`, or `Pry::Method` object.
|
49
|
+
#
|
50
|
+
# @param [::Method, UnboundMethod, Proc, Pry::Method] meth The method
|
51
|
+
# object.
|
52
|
+
# @param [Integer, nil] start_line The line number to start on, or nil to
|
53
|
+
# use the method's original line numbers.
|
54
|
+
# @return [Code]
|
55
|
+
def from_method(meth, start_line = nil)
|
56
|
+
meth = Pry::Method(meth)
|
57
|
+
start_line ||= meth.source_line || 1
|
58
|
+
new(meth.source, start_line, meth.source_type)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Attempt to extract the source code for module (or class) `mod`.
|
62
|
+
#
|
63
|
+
# @param [Module, Class] mod The module (or class) of interest.
|
64
|
+
# @param [Integer] candidate_rank The module candidate (by rank)
|
65
|
+
# to use (see `Pry::WrappedModule::Candidate` for more information).
|
66
|
+
# @param [Integer, nil] start_line The line number to start on, or nil to
|
67
|
+
# use the method's original line numbers.
|
68
|
+
# @return [Code]
|
69
|
+
def from_module(mod, candidate_rank = 0, start_line = nil)
|
70
|
+
candidate = Pry::WrappedModule(mod).candidate(candidate_rank)
|
71
|
+
start_line ||= candidate.line
|
72
|
+
new(candidate.source, start_line, :ruby)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [Symbol] The type of code stored in this wrapper.
|
77
|
+
attr_accessor :code_type
|
78
|
+
|
79
|
+
# Instantiate a `Code` object containing code from the given `Array`,
|
80
|
+
# `String`, or `IO`. The first line will be line 1 unless specified
|
81
|
+
# otherwise. If you need non-contiguous line numbers, you can create an
|
82
|
+
# empty `Code` object and then use `#push` to insert the lines.
|
83
|
+
#
|
84
|
+
# @param [Array<String>, String, IO] lines
|
85
|
+
# @param [Integer?] start_line
|
86
|
+
# @param [Symbol?] code_type
|
87
|
+
def initialize(lines = [], start_line = 1, code_type = :ruby)
|
88
|
+
if lines.is_a? String
|
89
|
+
lines = lines.lines
|
90
|
+
end
|
91
|
+
@lines = lines.each_with_index.map { |line, lineno|
|
92
|
+
LOC.new(line, lineno + start_line.to_i) }
|
93
|
+
@code_type = code_type
|
94
|
+
|
95
|
+
@with_marker = @with_indentation = @with_line_numbers = nil
|
96
|
+
end
|
97
|
+
|
98
|
+
# Append the given line. +lineno+ is one more than the last existing
|
99
|
+
# line, unless specified otherwise.
|
100
|
+
#
|
101
|
+
# @param [String] line
|
102
|
+
# @param [Integer?] lineno
|
103
|
+
# @return [String] The inserted line.
|
104
|
+
def push(line, lineno = nil)
|
105
|
+
if lineno.nil?
|
106
|
+
lineno = @lines.last.lineno + 1
|
107
|
+
end
|
108
|
+
@lines.push(LOC.new(line, lineno))
|
109
|
+
line
|
110
|
+
end
|
111
|
+
alias << push
|
112
|
+
|
113
|
+
# Filter the lines using the given block.
|
114
|
+
#
|
115
|
+
# @yield [LOC]
|
116
|
+
# @return [Code]
|
117
|
+
def select(&block)
|
118
|
+
alter do
|
119
|
+
@lines = @lines.select(&block)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Remove all lines that aren't in the given range, expressed either as a
|
124
|
+
# `Range` object or a first and last line number (inclusive). Negative
|
125
|
+
# indices count from the end of the array of lines.
|
126
|
+
#
|
127
|
+
# @param [Range, Integer] start_line
|
128
|
+
# @param [Integer?] end_line
|
129
|
+
# @return [Code]
|
130
|
+
def between(start_line, end_line = nil)
|
131
|
+
return self unless start_line
|
132
|
+
|
133
|
+
code_range = CodeRange.new(start_line, end_line)
|
134
|
+
|
135
|
+
alter do
|
136
|
+
@lines = @lines[code_range.indices_range(@lines)] || []
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Take `num_lines` from `start_line`, forward or backwards.
|
141
|
+
#
|
142
|
+
# @param [Integer] start_line
|
143
|
+
# @param [Integer] num_lines
|
144
|
+
# @return [Code]
|
145
|
+
def take_lines(start_line, num_lines)
|
146
|
+
start_idx =
|
147
|
+
if start_line >= 0
|
148
|
+
@lines.index { |loc| loc.lineno >= start_line } || @lines.length
|
149
|
+
else
|
150
|
+
[@lines.length + start_line, 0].max
|
151
|
+
end
|
152
|
+
|
153
|
+
alter do
|
154
|
+
@lines = @lines.slice(start_idx, num_lines)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Remove all lines except for the +lines+ up to and excluding +lineno+.
|
159
|
+
#
|
160
|
+
# @param [Integer] lineno
|
161
|
+
# @param [Integer] lines
|
162
|
+
# @return [Code]
|
163
|
+
def before(lineno, lines = 1)
|
164
|
+
return self unless lineno
|
165
|
+
|
166
|
+
select do |loc|
|
167
|
+
loc.lineno >= lineno - lines && loc.lineno < lineno
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# Remove all lines except for the +lines+ on either side of and including
|
172
|
+
# +lineno+.
|
173
|
+
#
|
174
|
+
# @param [Integer] lineno
|
175
|
+
# @param [Integer] lines
|
176
|
+
# @return [Code]
|
177
|
+
def around(lineno, lines = 1)
|
178
|
+
return self unless lineno
|
179
|
+
|
180
|
+
select do |loc|
|
181
|
+
loc.lineno >= lineno - lines && loc.lineno <= lineno + lines
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# Remove all lines except for the +lines+ after and excluding +lineno+.
|
186
|
+
#
|
187
|
+
# @param [Integer] lineno
|
188
|
+
# @param [Integer] lines
|
189
|
+
# @return [Code]
|
190
|
+
def after(lineno, lines = 1)
|
191
|
+
return self unless lineno
|
192
|
+
|
193
|
+
select do |loc|
|
194
|
+
loc.lineno > lineno && loc.lineno <= lineno + lines
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
# Remove all lines that don't match the given `pattern`.
|
199
|
+
#
|
200
|
+
# @param [Regexp] pattern
|
201
|
+
# @return [Code]
|
202
|
+
def grep(pattern)
|
203
|
+
return self unless pattern
|
204
|
+
|
205
|
+
pattern = Regexp.new(pattern)
|
206
|
+
|
207
|
+
select do |loc|
|
208
|
+
loc.line =~ pattern
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
# Format output with line numbers next to it, unless `y_n` is falsy.
|
213
|
+
#
|
214
|
+
# @param [Boolean?] y_n
|
215
|
+
# @return [Code]
|
216
|
+
def with_line_numbers(y_n = true)
|
217
|
+
alter do
|
218
|
+
@with_line_numbers = y_n
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Format output with a marker next to the given +lineno+, unless +lineno+ is
|
223
|
+
# falsy.
|
224
|
+
#
|
225
|
+
# @param [Integer?] lineno
|
226
|
+
# @return [Code]
|
227
|
+
def with_marker(lineno = 1)
|
228
|
+
alter do
|
229
|
+
@with_marker = !!lineno
|
230
|
+
@marker_lineno = lineno
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
# Format output with the specified number of spaces in front of every line,
|
235
|
+
# unless `spaces` is falsy.
|
236
|
+
#
|
237
|
+
# @param [Integer?] spaces
|
238
|
+
# @return [Code]
|
239
|
+
def with_indentation(spaces = 0)
|
240
|
+
alter do
|
241
|
+
@with_indentation = !!spaces
|
242
|
+
@indentation_num = spaces
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
# @return [String]
|
247
|
+
def inspect
|
248
|
+
Object.instance_method(:to_s).bind(self).call
|
249
|
+
end
|
250
|
+
|
251
|
+
# @return [Integer] the number of digits in the last line.
|
252
|
+
def max_lineno_width
|
253
|
+
@lines.length > 0 ? @lines.last.lineno.to_s.length : 0
|
254
|
+
end
|
255
|
+
|
256
|
+
# @return [String] a formatted representation (based on the configuration of
|
257
|
+
# the object).
|
258
|
+
def to_s
|
259
|
+
print_to_output("", false)
|
260
|
+
end
|
261
|
+
|
262
|
+
# @return [String] a (possibly highlighted) copy of the source code.
|
263
|
+
def highlighted
|
264
|
+
print_to_output("", true)
|
265
|
+
end
|
266
|
+
|
267
|
+
# Writes a formatted representation (based on the configuration of the
|
268
|
+
# object) to the given output, which must respond to `#<<`.
|
269
|
+
def print_to_output(output, color = false)
|
270
|
+
@lines.each do |loc|
|
271
|
+
loc = loc.dup
|
272
|
+
loc.colorize(@code_type) if color
|
273
|
+
loc.add_line_number(max_lineno_width, color) if @with_line_numbers
|
274
|
+
loc.add_marker(@marker_lineno) if @with_marker
|
275
|
+
loc.indent(@indentation_num) if @with_indentation
|
276
|
+
output << loc.line
|
277
|
+
output << "\n"
|
278
|
+
end
|
279
|
+
output
|
280
|
+
end
|
281
|
+
|
282
|
+
# Get the comment that describes the expression on the given line number.
|
283
|
+
#
|
284
|
+
# @param [Integer] line_number (1-based)
|
285
|
+
# @return [String] the code.
|
286
|
+
def comment_describing(line_number)
|
287
|
+
self.class.comment_describing(raw, line_number)
|
288
|
+
end
|
289
|
+
|
290
|
+
# Get the multiline expression that starts on the given line number.
|
291
|
+
#
|
292
|
+
# @param [Integer] line_number (1-based)
|
293
|
+
# @return [String] the code.
|
294
|
+
def expression_at(line_number, consume = 0)
|
295
|
+
self.class.expression_at(raw, line_number, consume: consume)
|
296
|
+
end
|
297
|
+
|
298
|
+
# Get the (approximate) Module.nesting at the give line number.
|
299
|
+
#
|
300
|
+
# @param [Integer] line_number line number starting from 1
|
301
|
+
# @return [Array<Module>] a list of open modules.
|
302
|
+
def nesting_at(line_number)
|
303
|
+
Pry::Indent.nesting_at(raw, line_number)
|
304
|
+
end
|
305
|
+
|
306
|
+
# Return an unformatted String of the code.
|
307
|
+
#
|
308
|
+
# @return [String]
|
309
|
+
def raw
|
310
|
+
@lines.map(&:line).join("\n") << "\n"
|
311
|
+
end
|
312
|
+
|
313
|
+
# Return the number of lines stored.
|
314
|
+
#
|
315
|
+
# @return [Integer]
|
316
|
+
def length
|
317
|
+
@lines ? @lines.length : 0
|
318
|
+
end
|
319
|
+
|
320
|
+
# Two `Code` objects are equal if they contain the same lines with the same
|
321
|
+
# numbers. Otherwise, call `to_s` and `chomp` and compare as Strings.
|
322
|
+
#
|
323
|
+
# @param [Code, Object] other
|
324
|
+
# @return [Boolean]
|
325
|
+
def ==(other)
|
326
|
+
if other.is_a?(Code)
|
327
|
+
other_lines = other.instance_variable_get(:@lines)
|
328
|
+
@lines.each_with_index.all? { |loc, i| loc == other_lines[i] }
|
329
|
+
else
|
330
|
+
to_s.chomp == other.to_s.chomp
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
# Forward any missing methods to the output of `#to_s`.
|
335
|
+
def method_missing(name, *args, &block)
|
336
|
+
to_s.send(name, *args, &block)
|
337
|
+
end
|
338
|
+
undef =~
|
339
|
+
|
340
|
+
# Check whether String responds to missing methods.
|
341
|
+
def respond_to_missing?(name, include_all = false)
|
342
|
+
''.respond_to?(name, include_all)
|
343
|
+
end
|
344
|
+
|
345
|
+
protected
|
346
|
+
|
347
|
+
# An abstraction of the `dup.instance_eval` pattern used throughout this
|
348
|
+
# class.
|
349
|
+
def alter(&block)
|
350
|
+
dup.tap { |o| o.instance_eval(&block) }
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|