From 502a8764fe6da814015b29a4db6b6c8d54e94d30 Mon Sep 17 00:00:00 2001 From: David Palm Date: Tue, 31 May 2011 13:33:19 +0200 Subject: [PATCH 1/5] Refactored Pry::Helpers::BaseHelpers#gem_installed? to use Gem::Specification.find_all_by_name rather than the deprecated Gem.source_index Refactored gem-list to use Gem::Specification.each rather than the deprecated Gem.source_index Changed gem-cd to use Gem::Specification.each rather than the deprecated Gem.source_index --- lib/pry/commands.rb | 10 +++++----- lib/pry/helpers/base_helpers.rb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb index c683bc3d..5250c8ff 100644 --- a/lib/pry/commands.rb +++ b/lib/pry/commands.rb @@ -238,8 +238,8 @@ e.g: gist -d my_method command "gem-cd", "Change working directory to specified gem's directory." do |gem_name| require 'rubygems' - gem_spec = Gem.source_index.find_name(gem_name).first - next output.puts("Gem `#{gem_name}` not found.") if !gem_spec + gem_spec = Gem::Specification.find_all_by_name(gem_name).first # find_by_name raises Gem::LoadError which is irksome + next output.puts("Gem `#{gem_name}` not found.") unless gem_spec Dir.chdir(File.expand_path(gem_spec.full_gem_path)) end @@ -330,13 +330,13 @@ e.g: gist -d my_method command "gem-list", "List/search installed gems. (Optional parameter: a regexp to limit the search)" do |arg| - gems = Gem.source_index.gems.values.group_by(&:name) if arg query = Regexp.new(arg, Regexp::IGNORECASE) - gems = gems.select { |gemname, specs| gemname =~ query } + else + query = // end - gems.each do |gemname, specs| + Gem::Specification.select{|spec| spec.name =~ query }.group_by(&:name).each do |gemname, specs| versions = specs.map(&:version).sort.reverse.map(&:to_s) versions = ["#{versions.first}"] + versions[1..-1].map{|v| "#{v}" } diff --git a/lib/pry/helpers/base_helpers.rb b/lib/pry/helpers/base_helpers.rb index 8d5f5dfe..048ad3e5 100644 --- a/lib/pry/helpers/base_helpers.rb +++ b/lib/pry/helpers/base_helpers.rb @@ -6,7 +6,7 @@ class Pry def gem_installed?(gem_name) require 'rubygems' - !!Gem.source_index.find_name(gem_name).first + !Gem::Specification.find_all_by_name(gem_name).empty? end def command_dependencies_met?(options) From 89f9e3c712d62f4f3259cf34a0a12c88854b60d7 Mon Sep 17 00:00:00 2001 From: David Palm Date: Tue, 31 May 2011 13:49:17 +0200 Subject: [PATCH 2/5] Adding backwards compat checks to ant-deprecation refactor (works with rubygems 1.8.x and 1.6.x) --- lib/pry/commands.rb | 11 +++++++++-- lib/pry/helpers/base_helpers.rb | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb index 5250c8ff..fd6e24e0 100644 --- a/lib/pry/commands.rb +++ b/lib/pry/commands.rb @@ -238,7 +238,8 @@ e.g: gist -d my_method command "gem-cd", "Change working directory to specified gem's directory." do |gem_name| require 'rubygems' - gem_spec = Gem::Specification.find_all_by_name(gem_name).first # find_by_name raises Gem::LoadError which is irksome + gem_spec = Gem::Specification.respond_to?(:each) ? Gem::Specification.find_all_by_name(gem_name).first : Gem.source_index.find_name(gem_name).first # find_by_name raises Gem::LoadError which is irksome + next output.puts("Gem `#{gem_name}` not found.") unless gem_spec Dir.chdir(File.expand_path(gem_spec.full_gem_path)) end @@ -335,8 +336,14 @@ e.g: gist -d my_method else query = // end + + if Gem::Specification.respond_to?(:each) + gems = Gem::Specification.select{|spec| spec.name =~ query }.group_by(&:name) + else + gems = Gem.source_index.gems.values.group_by(&:name).select { |gemname, specs| gemname =~ query } + end - Gem::Specification.select{|spec| spec.name =~ query }.group_by(&:name).each do |gemname, specs| + gems.each do |gemname, specs| versions = specs.map(&:version).sort.reverse.map(&:to_s) versions = ["#{versions.first}"] + versions[1..-1].map{|v| "#{v}" } diff --git a/lib/pry/helpers/base_helpers.rb b/lib/pry/helpers/base_helpers.rb index 048ad3e5..f00a9641 100644 --- a/lib/pry/helpers/base_helpers.rb +++ b/lib/pry/helpers/base_helpers.rb @@ -6,7 +6,7 @@ class Pry def gem_installed?(gem_name) require 'rubygems' - !Gem::Specification.find_all_by_name(gem_name).empty? + Gem::Specification.respond_to?(:find_all_by_name) ? !Gem::Specification.find_all_by_name(gem_name).empty? : Gem.source_index.find_name(gem_name).first end def command_dependencies_met?(options) From 164ff2bf6a2a5a84b513bdc21fc719c34d1702dc Mon Sep 17 00:00:00 2001 From: David Palm Date: Tue, 31 May 2011 15:46:26 +0200 Subject: [PATCH 3/5] Adding rake ruby:gemspec to dump a .gemspec file so I can bundle the gem from github Adding generated gemspec file --- Rakefile | 7 +++++++ pry-0.8.3.gemspec | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 pry-0.8.3.gemspec diff --git a/Rakefile b/Rakefile index c1352392..1f66eb2f 100644 --- a/Rakefile +++ b/Rakefile @@ -52,6 +52,13 @@ namespace :ruby do pkg.need_zip = false pkg.need_tar = false end + + desc "Generate gemspec file" + task :gemspec do + File.open("#{spec.name}-#{spec.version}.gemspec", "w") do |f| + f << spec.to_ruby + end + end end [:mingw32, :mswin32].each do |v| diff --git a/pry-0.8.3.gemspec b/pry-0.8.3.gemspec new file mode 100644 index 00000000..090ab750 --- /dev/null +++ b/pry-0.8.3.gemspec @@ -0,0 +1,44 @@ +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{pry} + s.version = "0.8.3" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["John Mair (banisterfiend)"] + s.date = %q{2011-05-31} + s.default_executable = %q{pry} + s.description = %q{attach an irb-like session to any object at runtime} + s.email = %q{jrmair@gmail.com} + s.executables = ["pry"] + s.files = [".document", ".gemtest", ".gitignore", ".yardopts", "CHANGELOG", "LICENSE", "README.markdown", "Rakefile", "TODO", "bin/pry", "examples/example_basic.rb", "examples/example_command_override.rb", "examples/example_commands.rb", "examples/example_hooks.rb", "examples/example_image_edit.rb", "examples/example_input.rb", "examples/example_input2.rb", "examples/example_output.rb", "examples/example_print.rb", "examples/example_prompt.rb", "lib/pry.rb", "lib/pry/command_context.rb", "lib/pry/command_processor.rb", "lib/pry/command_set.rb", "lib/pry/commands.rb", "lib/pry/completion.rb", "lib/pry/core_extensions.rb", "lib/pry/custom_completions.rb", "lib/pry/helpers.rb", "lib/pry/helpers/base_helpers.rb", "lib/pry/helpers/command_helpers.rb", "lib/pry/hooks.rb", "lib/pry/print.rb", "lib/pry/prompts.rb", "lib/pry/pry_class.rb", "lib/pry/pry_instance.rb", "lib/pry/version.rb", "test/test.rb", "test/test_helper.rb", "test/testrc", "wiki/Customizing-pry.md", "wiki/Home.md"] + s.homepage = %q{http://banisterfiend.wordpress.com} + s.require_paths = ["lib"] + s.rubygems_version = %q{1.6.2} + s.summary = %q{attach an irb-like session to any object at runtime} + s.test_files = ["test/test.rb", "test/test_helper.rb", "test/testrc"] + + if s.respond_to? :specification_version then + s.specification_version = 3 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, [">= 2.0.5"]) + s.add_runtime_dependency(%q, [">= 0.9.8"]) + s.add_runtime_dependency(%q, [">= 1.5.5"]) + s.add_runtime_dependency(%q, [">= 0.4.0"]) + s.add_development_dependency(%q, [">= 1.1.0"]) + else + s.add_dependency(%q, [">= 2.0.5"]) + s.add_dependency(%q, [">= 0.9.8"]) + s.add_dependency(%q, [">= 1.5.5"]) + s.add_dependency(%q, [">= 0.4.0"]) + s.add_dependency(%q, [">= 1.1.0"]) + end + else + s.add_dependency(%q, [">= 2.0.5"]) + s.add_dependency(%q, [">= 0.9.8"]) + s.add_dependency(%q, [">= 1.5.5"]) + s.add_dependency(%q, [">= 0.4.0"]) + s.add_dependency(%q, [">= 1.1.0"]) + end +end From 7fe09c806dbd9b7d2d6f220c77b21e79f43e4c05 Mon Sep 17 00:00:00 2001 From: David Palm Date: Wed, 1 Jun 2011 08:29:48 +0200 Subject: [PATCH 4/5] whitespace --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index fb3f9b05..e658f4f6 100644 --- a/Rakefile +++ b/Rakefile @@ -56,7 +56,7 @@ namespace :ruby do task :gemspec do File.open("#{spec.name}-#{spec.version}.gemspec", "w") do |f| f << spec.to_ruby -end + end end end From bafff3dc7df0c70825189ffa35c05c7c74a0dfcf Mon Sep 17 00:00:00 2001 From: David Palm Date: Wed, 1 Jun 2011 08:47:14 +0200 Subject: [PATCH 5/5] rubygems 1.8.x compatibility fixes applied to dev branch --- lib/pry/default_commands/gems.rb | 10 +++++++--- lib/pry/plugins.rb | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/pry/default_commands/gems.rb b/lib/pry/default_commands/gems.rb index 62f016a7..3f2d4421 100644 --- a/lib/pry/default_commands/gems.rb +++ b/lib/pry/default_commands/gems.rb @@ -19,14 +19,18 @@ class Pry end command "gem-cd", "Change working directory to specified gem's directory.", :argument_required => true do |gem| - spec = Gem.source_index.find_name(gem).sort { |a,b| Gem::Version.new(b.version) <=> Gem::Version.new(a.version) }.first + specs = Gem::Specification.respond_to?(:each) ? Gem::Specification.find_all_by_name(gem) : Gem.source_index.find_name(gem) + spec = specs.sort { |a,b| Gem::Version.new(b.version) <=> Gem::Version.new(a.version) }.first spec ? Dir.chdir(spec.full_gem_path) : output.puts("Gem `#{gem}` not found.") end - command "gem-list", "List/search installed gems. (Optional parameter: a regexp to limit the search)" do |pattern| pattern = Regexp.new pattern.to_s, Regexp::IGNORECASE - gems = Gem.source_index.find_name(pattern).group_by(&:name) + gems = if Gem::Specification.respond_to?(:each) + Gem::Specification.select{|spec| spec.name =~ pattern }.group_by(&:name) + else + Gem.source_index.gems.values.group_by(&:name).select { |gemname, specs| gemname =~ pattern } + end gems.each do |gem, specs| specs.sort! do |a,b| diff --git a/lib/pry/plugins.rb b/lib/pry/plugins.rb index 70b0fa94..b8c4f4b6 100644 --- a/lib/pry/plugins.rb +++ b/lib/pry/plugins.rb @@ -44,7 +44,7 @@ class Pry # Find all installed Pry plugins and store them in an internal array. def locate_plugins Gem.refresh - Gem.source_index.find_name('').each do |gem| + (Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem| next if gem.name !~ PRY_PLUGIN_PREFIX plugin_name = gem.name.split('-', 2).last @plugins << Plugin.new(plugin_name, gem.name, true) if !gem_located?(gem.name)