diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ce465061..9a452bab 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -177,7 +177,6 @@ Style/DoubleNegation: Exclude: - 'lib/pry/code.rb' - 'lib/pry/command_set.rb' - - 'lib/pry/commands/gist.rb' - 'lib/pry/commands/whereami.rb' - 'lib/pry/method.rb' - 'lib/pry/method/weird_method_locator.rb' diff --git a/Gemfile b/Gemfile index 2c91fced..38b2faae 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,6 @@ source 'https://rubygems.org' gemspec gem 'rake', '~> 10.0' -gem 'gist' gem 'yard' gem 'rspec', '~> 3.8.0' gem 'simplecov', '~> 0.16', require: false diff --git a/lib/pry.rb b/lib/pry.rb index 04a1666b..08f84246 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -109,7 +109,6 @@ require 'pry/commands/gem_open' require 'pry/commands/gem_readme' require 'pry/commands/gem_search' require 'pry/commands/gem_stats' -require 'pry/commands/gist' require 'pry/commands/help' require 'pry/commands/hist' require 'pry/commands/import_set' diff --git a/lib/pry/commands/code_collector.rb b/lib/pry/commands/code_collector.rb index f78ff4e2..8e2df26a 100644 --- a/lib/pry/commands/code_collector.rb +++ b/lib/pry/commands/code_collector.rb @@ -101,10 +101,10 @@ class Pry # @return [String] def pry_output_content pry_array_content_as_string( - _pry_.output_ring, self.class.output_result_ranges - ) do |v| - _pry_.config.gist.inspecter.call(v) - end + _pry_.output_ring, + self.class.output_result_ranges, + &:pretty_inspect + ) end # The selected `_pry_.input_ring` as a string, as specified by diff --git a/lib/pry/commands/gist.rb b/lib/pry/commands/gist.rb deleted file mode 100644 index 0cf36431..00000000 --- a/lib/pry/commands/gist.rb +++ /dev/null @@ -1,103 +0,0 @@ -class Pry - class Command - class Gist < Pry::ClassCommand - match 'gist' - group 'Misc' - description 'Upload code, docs, history to https://gist.github.com/.' - command_options requires_gem: "gist" - - banner <<-'BANNER' - Usage: gist [OPTIONS] [--help] - - The gist command enables you to gist code from files and methods to github. - - gist -i 20 --lines 1..3 - gist Pry#repl --lines 1..-1 - gist Rakefile --lines 5 - BANNER - - def setup - require 'gist' - end - - def options(opt) - CodeCollector.inject_options(opt) - opt.on :login, "Authenticate the gist gem with GitHub" - opt.on :p, :public, "Create a public gist (default: false)", default: false - opt.on :clip, "Copy the selected content to clipboard instead, do NOT " \ - "gist it", default: false - end - - def process - return ::Gist.login! if opts.present?(:login) - - cc = CodeCollector.new(args, opts, _pry_) - - raise CommandError, "Found no code to gist." if cc.content =~ /\A\s*\z/ - - if opts.present?(:clip) - clipboard_content(cc.content) - else - # we're overriding the default behavior of the 'in' option (as - # defined on CodeCollector) with our local behaviour. - content = opts.present?(:in) ? input_content : cc.content - gist_content content, cc.file - end - end - - def clipboard_content(content) - ::Gist.copy(content) - output.puts "Copied content to clipboard!" - end - - def input_content - content = "" - CodeCollector.input_expression_ranges.each do |range| - input_expressions = _pry_.input_ring[range] || [] - Array(input_expressions).each_with_index do |code, index| - corrected_index = index + range.first - next unless code && code != "" - - content << code - next unless code !~ /;\Z/ - - content << comment_expression_result_for_gist( - _pry_.config.gist.inspecter.call(_pry_.output_ring[corrected_index]) - ).to_s - end - end - - content - end - - def comment_expression_result_for_gist(result) - content = "" - result.lines.each_with_index do |line, index| - content << index == 0 ? "# => #{line}" : "# #{line}" - end - - content - end - - def gist_content(content, filename) - response = ::Gist.gist( - content, filename: filename || "pry_gist.rb", public: !!opts[:p] - ) - if response - url = response['html_url'] - message = "Gist created at URL #{url}" - begin - ::Gist.copy(url) - message << ", which is now in the clipboard." - rescue ::Gist::ClipboardError # rubocop:disable Lint/HandleExceptions - end - - output.puts message - end - end - end - - Pry::Commands.add_command(Pry::Command::Gist) - Pry::Commands.alias_command 'clipit', 'gist --clip' - end -end diff --git a/lib/pry/config.rb b/lib/pry/config.rb index 5e6e1380..22ebc72f 100644 --- a/lib/pry/config.rb +++ b/lib/pry/config.rb @@ -119,7 +119,6 @@ class Pry file_completions: proc { Dir["."] }, ls: Pry::Config.from_hash(Pry::Command::Ls::DEFAULT_OPTIONS), completer: Pry::InputCompleter, - gist: Pry::Config.from_hash(inspecter: proc(&:pretty_inspect)), history: Pry::Config.from_hash( should_save: true, should_load: true ).tap do |history| diff --git a/spec/commands/gist_spec.rb b/spec/commands/gist_spec.rb deleted file mode 100644 index 3630dd57..00000000 --- a/spec/commands/gist_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# These tests are out of date. -# They need to be updated for the new 'gist' API, but im too sleepy to -# do that now. -describe 'gist' do - it 'has a dependency on the jist gem' do - expect(Pry::Command::Gist.command_options[:requires_gem]).to eq("gist") - end - - before do - Pad.gist_calls = {} - end - - # In absence of normal mocking, just monkeysmash these with no undoing after. - module ::Gist # rubocop:disable Style/ClassAndModuleChildren - class << self - def login! - Pad.gist_calls[:login!] = true - end - - def gist(*args) - Pad.gist_calls[:gist_args] = args - { 'html_url' => 'http://gist.blahblah' } - end - - def copy(content) - Pad.gist_calls[:copy_args] = content - end - end - end - - it 'nominally logs in' do - pry_eval 'gist --login' - expect(Pad.gist_calls[:login!]).not_to be_nil - end -end