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,261 @@
|
|
1
|
+
class Pry
|
2
|
+
class REPL
|
3
|
+
extend Pry::Forwardable
|
4
|
+
def_delegators :@pry, :input, :output
|
5
|
+
|
6
|
+
# @return [Pry] The instance of {Pry} that the user is controlling.
|
7
|
+
attr_accessor :pry
|
8
|
+
|
9
|
+
# Instantiate a new {Pry} instance with the given options, then start a
|
10
|
+
# {REPL} instance wrapping it.
|
11
|
+
# @option options See {Pry#initialize}
|
12
|
+
def self.start(options)
|
13
|
+
new(Pry.new(options)).start
|
14
|
+
end
|
15
|
+
|
16
|
+
# Create an instance of {REPL} wrapping the given {Pry}.
|
17
|
+
# @param [Pry] pry The instance of {Pry} that this {REPL} will control.
|
18
|
+
# @param [Hash] options Options for this {REPL} instance.
|
19
|
+
# @option options [Object] :target The initial target of the session.
|
20
|
+
def initialize(pry, options = {})
|
21
|
+
@pry = pry
|
22
|
+
@indent = Pry::Indent.new
|
23
|
+
|
24
|
+
@readline_output = nil
|
25
|
+
|
26
|
+
if options[:target]
|
27
|
+
@pry.push_binding options[:target]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Start the read-eval-print loop.
|
32
|
+
# @return [Object?] If the session throws `:breakout`, return the value
|
33
|
+
# thrown with it.
|
34
|
+
# @raise [Exception] If the session throws `:raise_up`, raise the exception
|
35
|
+
# thrown with it.
|
36
|
+
def start
|
37
|
+
prologue
|
38
|
+
Pry::InputLock.for(:all).with_ownership { repl }
|
39
|
+
ensure
|
40
|
+
epilogue
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# Set up the repl session.
|
46
|
+
# @return [void]
|
47
|
+
def prologue
|
48
|
+
pry.exec_hook :before_session, pry.output, pry.current_binding, pry
|
49
|
+
|
50
|
+
# Clear the line before starting Pry. This fixes issue #566.
|
51
|
+
if pry.config.correct_indent
|
52
|
+
Kernel.print(Helpers::Platform.windows_ansi? ? "\e[0F" : "\e[0G")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# The actual read-eval-print loop.
|
57
|
+
#
|
58
|
+
# The {REPL} instance is responsible for reading and looping, whereas the
|
59
|
+
# {Pry} instance is responsible for evaluating user input and printing
|
60
|
+
# return values and command output.
|
61
|
+
#
|
62
|
+
# @return [Object?] If the session throws `:breakout`, return the value
|
63
|
+
# thrown with it.
|
64
|
+
# @raise [Exception] If the session throws `:raise_up`, raise the exception
|
65
|
+
# thrown with it.
|
66
|
+
def repl
|
67
|
+
loop do
|
68
|
+
case val = read
|
69
|
+
when :control_c
|
70
|
+
output.puts ""
|
71
|
+
pry.reset_eval_string
|
72
|
+
when :no_more_input
|
73
|
+
output.puts "" if output.tty?
|
74
|
+
break
|
75
|
+
else
|
76
|
+
output.puts "" if val.nil? && output.tty?
|
77
|
+
return pry.exit_value unless pry.eval(val)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Clean up after the repl session.
|
83
|
+
# @return [void]
|
84
|
+
def epilogue
|
85
|
+
pry.exec_hook :after_session, pry.output, pry.current_binding, pry
|
86
|
+
end
|
87
|
+
|
88
|
+
# Read a line of input from the user.
|
89
|
+
# @return [String] The line entered by the user.
|
90
|
+
# @return [nil] On `<Ctrl-D>`.
|
91
|
+
# @return [:control_c] On `<Ctrl+C>`.
|
92
|
+
# @return [:no_more_input] On EOF.
|
93
|
+
def read
|
94
|
+
@indent.reset if pry.eval_string.empty?
|
95
|
+
current_prompt = pry.select_prompt
|
96
|
+
indentation = pry.config.auto_indent ? @indent.current_prefix : ''
|
97
|
+
|
98
|
+
val = read_line("#{current_prompt}#{indentation}")
|
99
|
+
|
100
|
+
# Return nil for EOF, :no_more_input for error, or :control_c for <Ctrl-C>
|
101
|
+
return val unless String === val
|
102
|
+
|
103
|
+
if pry.config.auto_indent
|
104
|
+
original_val = "#{indentation}#{val}"
|
105
|
+
indented_val = @indent.indent(val)
|
106
|
+
|
107
|
+
if output.tty? && pry.config.correct_indent && Pry::Helpers::BaseHelpers.use_ansi_codes?
|
108
|
+
output.print @indent.correct_indentation(
|
109
|
+
current_prompt,
|
110
|
+
indented_val,
|
111
|
+
calculate_overhang(current_prompt, original_val, indented_val)
|
112
|
+
)
|
113
|
+
output.flush
|
114
|
+
end
|
115
|
+
else
|
116
|
+
indented_val = val
|
117
|
+
end
|
118
|
+
|
119
|
+
indented_val
|
120
|
+
end
|
121
|
+
|
122
|
+
# Manage switching of input objects on encountering `EOFError`s.
|
123
|
+
# @return [Object] Whatever the given block returns.
|
124
|
+
# @return [:no_more_input] Indicates that no more input can be read.
|
125
|
+
def handle_read_errors
|
126
|
+
should_retry = true
|
127
|
+
exception_count = 0
|
128
|
+
|
129
|
+
begin
|
130
|
+
yield
|
131
|
+
rescue EOFError
|
132
|
+
pry.config.input = Pry.config.input
|
133
|
+
if !should_retry
|
134
|
+
output.puts "Error: Pry ran out of things to read from! " \
|
135
|
+
"Attempting to break out of REPL."
|
136
|
+
return :no_more_input
|
137
|
+
end
|
138
|
+
should_retry = false
|
139
|
+
retry
|
140
|
+
|
141
|
+
# Handle <Ctrl+C> like Bash: empty the current input buffer, but don't
|
142
|
+
# quit. This is only for MRI 1.9; other versions of Ruby don't let you
|
143
|
+
# send Interrupt from within Readline.
|
144
|
+
rescue Interrupt
|
145
|
+
return :control_c
|
146
|
+
|
147
|
+
# If we get a random error when trying to read a line we don't want to
|
148
|
+
# automatically retry, as the user will see a lot of error messages
|
149
|
+
# scroll past and be unable to do anything about it.
|
150
|
+
rescue RescuableException => e
|
151
|
+
puts "Error: #{e.message}"
|
152
|
+
output.puts e.backtrace
|
153
|
+
exception_count += 1
|
154
|
+
if exception_count < 5
|
155
|
+
retry
|
156
|
+
end
|
157
|
+
puts "FATAL: Pry failed to get user input using `#{input}`."
|
158
|
+
puts "To fix this you may be able to pass input and output file " \
|
159
|
+
"descriptors to pry directly. e.g."
|
160
|
+
puts " Pry.config.input = STDIN"
|
161
|
+
puts " Pry.config.output = STDOUT"
|
162
|
+
puts " binding.pry"
|
163
|
+
return :no_more_input
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# Returns the next line of input to be sent to the {Pry} instance.
|
168
|
+
# @param [String] current_prompt The prompt to use for input.
|
169
|
+
# @return [String?] The next line of input, or `nil` on <Ctrl-D>.
|
170
|
+
def read_line(current_prompt)
|
171
|
+
handle_read_errors do
|
172
|
+
if coolline_available?
|
173
|
+
input.completion_proc = proc do |cool|
|
174
|
+
completions = @pry.complete cool.completed_word
|
175
|
+
completions.compact
|
176
|
+
end
|
177
|
+
elsif input.respond_to? :completion_proc=
|
178
|
+
input.completion_proc = proc do |inp|
|
179
|
+
@pry.complete inp
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
if readline_available?
|
184
|
+
set_readline_output
|
185
|
+
input_readline(current_prompt, false) # false since we'll add it manually
|
186
|
+
elsif coolline_available?
|
187
|
+
input_readline(current_prompt)
|
188
|
+
else
|
189
|
+
if input.method(:readline).arity == 1
|
190
|
+
input_readline(current_prompt)
|
191
|
+
else
|
192
|
+
input_readline
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def input_readline(*args)
|
199
|
+
Pry::InputLock.for(:all).interruptible_region do
|
200
|
+
input.readline(*args)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def readline_available?
|
205
|
+
defined?(Readline) && input == Readline
|
206
|
+
end
|
207
|
+
|
208
|
+
def coolline_available?
|
209
|
+
defined?(Coolline) && input.is_a?(Coolline)
|
210
|
+
end
|
211
|
+
|
212
|
+
# If `$stdout` is not a tty, it's probably a pipe.
|
213
|
+
# @example
|
214
|
+
# # `piping?` returns `false`
|
215
|
+
# % pry
|
216
|
+
# [1] pry(main)
|
217
|
+
#
|
218
|
+
# # `piping?` returns `true`
|
219
|
+
# % pry | tee log
|
220
|
+
def piping?
|
221
|
+
return false unless $stdout.respond_to?(:tty?)
|
222
|
+
|
223
|
+
!$stdout.tty? && $stdin.tty? && !Helpers::Platform.windows?
|
224
|
+
end
|
225
|
+
|
226
|
+
# @return [void]
|
227
|
+
def set_readline_output
|
228
|
+
return if @readline_output
|
229
|
+
|
230
|
+
if piping?
|
231
|
+
@readline_output = (Readline.output = Pry.config.output)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
# Calculates correct overhang for current line. Supports vi Readline
|
236
|
+
# mode and its indicators such as "(ins)" or "(cmd)".
|
237
|
+
#
|
238
|
+
# @return [Integer]
|
239
|
+
# @note This doesn't calculate overhang for Readline's emacs mode with an
|
240
|
+
# indicator because emacs is the default mode and it doesn't use
|
241
|
+
# indicators in 99% of cases.
|
242
|
+
def calculate_overhang(current_prompt, original_val, indented_val)
|
243
|
+
overhang = original_val.length - indented_val.length
|
244
|
+
|
245
|
+
if readline_available? && Readline.respond_to?(:vi_editing_mode?)
|
246
|
+
begin
|
247
|
+
# rb-readline doesn't support this method:
|
248
|
+
# https://github.com/ConnorAtherton/rb-readline/issues/152
|
249
|
+
if Readline.vi_editing_mode?
|
250
|
+
overhang += current_prompt.length - indented_val.length
|
251
|
+
end
|
252
|
+
rescue NotImplementedError
|
253
|
+
# VI editing mode is unsupported on JRuby.
|
254
|
+
# https://github.com/pry/pry/issues/1840
|
255
|
+
nil
|
256
|
+
end
|
257
|
+
end
|
258
|
+
[0, overhang].max
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class Pry
|
2
|
+
# A class to manage the loading of files through the REPL loop.
|
3
|
+
# This is an interesting trick as it processes your file as if it
|
4
|
+
# was user input in an interactive session. As a result, all Pry
|
5
|
+
# commands are available, and they are executed non-interactively. Furthermore
|
6
|
+
# the session becomes interactive when the repl loop processes a
|
7
|
+
# 'make-interactive' command in the file. The session also becomes
|
8
|
+
# interactive when an exception is encountered, enabling you to fix
|
9
|
+
# the error before returning to non-interactive processing with the
|
10
|
+
# 'make-non-interactive' command.
|
11
|
+
|
12
|
+
class REPLFileLoader
|
13
|
+
def initialize(file_name)
|
14
|
+
full_name = File.expand_path(file_name)
|
15
|
+
raise RuntimeError, "No such file: #{full_name}" if !File.exist?(full_name)
|
16
|
+
|
17
|
+
define_additional_commands
|
18
|
+
@content = File.read(full_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Switch to interactive mode, i.e take input from the user
|
22
|
+
# and use the regular print and exception handlers.
|
23
|
+
# @param [Pry] _pry_ the Pry instance to make interactive.
|
24
|
+
def interactive_mode(_pry_)
|
25
|
+
_pry_.config.input = Pry.config.input
|
26
|
+
_pry_.config.print = Pry.config.print
|
27
|
+
_pry_.config.exception_handler = Pry.config.exception_handler
|
28
|
+
Pry::REPL.new(_pry_).start
|
29
|
+
end
|
30
|
+
|
31
|
+
# Switch to non-interactive mode. Essentially
|
32
|
+
# this means there is no result output
|
33
|
+
# and that the session becomes interactive when an exception is encountered.
|
34
|
+
# @param [Pry] _pry_ the Pry instance to make non-interactive.
|
35
|
+
def non_interactive_mode(_pry_, content)
|
36
|
+
_pry_.print = proc {}
|
37
|
+
_pry_.exception_handler = proc do |o, e, _p_|
|
38
|
+
_p_.run_command "cat --ex"
|
39
|
+
o.puts "...exception encountered, going interactive!"
|
40
|
+
interactive_mode(_pry_)
|
41
|
+
end
|
42
|
+
|
43
|
+
content.lines.each do |line|
|
44
|
+
break unless _pry_.eval line, generated: true
|
45
|
+
end
|
46
|
+
|
47
|
+
unless _pry_.eval_string.empty?
|
48
|
+
_pry_.output.puts "#{_pry_.eval_string}...exception encountered, going interactive!"
|
49
|
+
interactive_mode(_pry_)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Define a few extra commands useful for flipping back & forth
|
54
|
+
# between interactive/non-interactive modes
|
55
|
+
def define_additional_commands
|
56
|
+
s = self
|
57
|
+
|
58
|
+
Pry::Commands.command "make-interactive", "Make the session interactive" do
|
59
|
+
s.interactive_mode(_pry_)
|
60
|
+
end
|
61
|
+
|
62
|
+
Pry::Commands.command "load-file", "Load another file through the repl" do |file_name|
|
63
|
+
s.non_interactive_mode(_pry_, File.read(File.expand_path(file_name)))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Actually load the file through the REPL by setting file content
|
68
|
+
# as the REPL input stream.
|
69
|
+
def load
|
70
|
+
non_interactive_mode(Pry.new, @content)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
class Pry
|
2
|
+
# A ring is a thread-safe fixed-capacity array to which you can only add
|
3
|
+
# elements. Older entries are overwritten as you add new elements, so that the
|
4
|
+
# ring can never contain more than `max_size` elemens.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# ring = Pry::Ring.new(3)
|
8
|
+
# ring << 1 << 2 << 3
|
9
|
+
# ring.to_a #=> [1, 2, 3]
|
10
|
+
# ring << 4
|
11
|
+
# ring.to_a #=> [2, 3, 4]
|
12
|
+
#
|
13
|
+
# ring[0] #=> 2
|
14
|
+
# ring[-1] #=> 4
|
15
|
+
# ring.clear
|
16
|
+
# ring[0] #=> nil
|
17
|
+
#
|
18
|
+
# @api public
|
19
|
+
# @since v0.12.0
|
20
|
+
class Ring
|
21
|
+
# @return [Integer] maximum buffer size
|
22
|
+
attr_reader :max_size
|
23
|
+
|
24
|
+
# @return [Integer] how many objects were added during the lifetime of the
|
25
|
+
# ring
|
26
|
+
attr_reader :count
|
27
|
+
alias size count
|
28
|
+
|
29
|
+
# @param [Integer] max_size Maximum buffer size. The buffer will start
|
30
|
+
# overwriting elements once its reaches its maximum capacity
|
31
|
+
def initialize(max_size)
|
32
|
+
@max_size = max_size
|
33
|
+
@mutex = Mutex.new
|
34
|
+
clear
|
35
|
+
end
|
36
|
+
|
37
|
+
# Push `value` to the current index.
|
38
|
+
#
|
39
|
+
# @param [Object] value
|
40
|
+
# @return [self]
|
41
|
+
def <<(value)
|
42
|
+
@mutex.synchronize do
|
43
|
+
@buffer[count % max_size] = value
|
44
|
+
@count += 1
|
45
|
+
self
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Read the value stored at `index`.
|
50
|
+
#
|
51
|
+
# @param [Integer, Range] index The element (if Integer) or elements
|
52
|
+
# (if Range) associated with `index`
|
53
|
+
# @return [Object, Array<Object>, nil] element(s) at `index`, `nil` if none
|
54
|
+
# exist
|
55
|
+
def [](index)
|
56
|
+
@mutex.synchronize do
|
57
|
+
return @buffer[(count + index) % max_size] if index.is_a?(Integer)
|
58
|
+
return @buffer[index] if count <= max_size
|
59
|
+
|
60
|
+
# Swap parts of array when the array turns page and starts overwriting
|
61
|
+
# from the beginning, then apply the range.
|
62
|
+
last_part = @buffer.slice([index.end, max_size - 1].min, count % max_size)
|
63
|
+
(last_part + (@buffer - last_part))[index]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Array<Object>] the buffer as unwinded array
|
68
|
+
def to_a
|
69
|
+
return @buffer.dup if count <= max_size
|
70
|
+
|
71
|
+
last_part = @buffer.slice(count % max_size, @buffer.size)
|
72
|
+
last_part + (@buffer - last_part)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Clear the buffer and reset count.
|
76
|
+
# @return [void]
|
77
|
+
def clear
|
78
|
+
@mutex.synchronize do
|
79
|
+
@buffer = []
|
80
|
+
@count = 0
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
module Rubygem
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def installed?(name)
|
8
|
+
if Gem::Specification.respond_to?(:find_all_by_name)
|
9
|
+
Gem::Specification.find_all_by_name(name).any?
|
10
|
+
else
|
11
|
+
Gem.source_index.find_name(name).first
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get the gem spec object for the given gem name.
|
16
|
+
#
|
17
|
+
# @param [String] name
|
18
|
+
# @return [Gem::Specification]
|
19
|
+
def spec(name)
|
20
|
+
specs = if Gem::Specification.respond_to?(:each)
|
21
|
+
Gem::Specification.find_all_by_name(name)
|
22
|
+
else
|
23
|
+
Gem.source_index.find_name(name)
|
24
|
+
end
|
25
|
+
|
26
|
+
first_spec = specs.sort_by { |spec| Gem::Version.new(spec.version) }.last
|
27
|
+
|
28
|
+
first_spec or raise CommandError, "Gem `#{name}` not found"
|
29
|
+
end
|
30
|
+
|
31
|
+
# List gems matching a pattern.
|
32
|
+
#
|
33
|
+
# @param [Regexp] pattern
|
34
|
+
# @return [Array<Gem::Specification>]
|
35
|
+
def list(pattern = /.*/)
|
36
|
+
if Gem::Specification.respond_to?(:each)
|
37
|
+
Gem::Specification.select { |spec| spec.name =~ pattern }
|
38
|
+
else
|
39
|
+
Gem.source_index.gems.values.select { |spec| spec.name =~ pattern }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Completion function for gem-cd and gem-open.
|
44
|
+
#
|
45
|
+
# @param [String] so_far what the user's typed so far
|
46
|
+
# @return [Array<String>] completions
|
47
|
+
def complete(so_far)
|
48
|
+
if so_far =~ / ([^ ]*)\z/
|
49
|
+
self.list(%r{\A#{$2}}).map(&:name)
|
50
|
+
else
|
51
|
+
self.list.map(&:name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Installs a gem with all its dependencies.
|
56
|
+
#
|
57
|
+
# @param [String] name
|
58
|
+
# @return [void]
|
59
|
+
def install(name)
|
60
|
+
require 'rubygems/dependency_installer'
|
61
|
+
gem_config = Gem.configuration['gem']
|
62
|
+
gemrc_opts = (gem_config.nil? ? "" : gem_config.split(' '))
|
63
|
+
destination = if gemrc_opts.include?('--user-install')
|
64
|
+
Gem.user_dir
|
65
|
+
elsif File.writable?(Gem.dir)
|
66
|
+
Gem.dir
|
67
|
+
else
|
68
|
+
Gem.user_dir
|
69
|
+
end
|
70
|
+
installer = Gem::DependencyInstaller.new(install_dir: destination)
|
71
|
+
installer.install(name)
|
72
|
+
rescue Errno::EACCES
|
73
|
+
raise CommandError,
|
74
|
+
"Insufficient permissions to install #{green(name)}."
|
75
|
+
rescue Gem::GemNotFoundException
|
76
|
+
raise CommandError,
|
77
|
+
"Gem #{green(name)} not found. Aborting installation."
|
78
|
+
else
|
79
|
+
Gem.refresh
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|