diff options
author | Tony Spataro <tony@rightscale.com> | 2015-06-19 12:08:39 -0700 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2015-06-19 18:02:53 -0500 |
commit | e5d936e7c6265f8f8dcdd7fcc4b93aeb013acbd1 (patch) | |
tree | 52ebecbb7c3efca5a39fd4053cda3d6f2d97d9a0 /lib/bundler/remote_specification.rb | |
parent | 3f4f6286c56765e8c4968631643106cfd534b789 (diff) | |
download | bundler-e5d936e7c6265f8f8dcdd7fcc4b93aeb013acbd1.tar.gz |
Make Bundler::RemoteSpecification comparable.
Uses a comparison strategy borrowed from RubyGems 2.23 for maximum
compatibility with Gem::Specification et. al.
Diffstat (limited to 'lib/bundler/remote_specification.rb')
-rw-r--r-- | lib/bundler/remote_specification.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/bundler/remote_specification.rb b/lib/bundler/remote_specification.rb index d8bd5c331f..36f62af7e4 100644 --- a/lib/bundler/remote_specification.rb +++ b/lib/bundler/remote_specification.rb @@ -34,9 +34,12 @@ module Bundler end end + # Compare this specification against another object. Using sort_obj + # is compatible with Gem::Specification and other Bundler or RubyGems + # objects. Otherwise, use the default Object comparison. def <=>(other) - if other.respond_to?(:full_name) - full_name <=> other.full_name + if other.respond_to?(:sort_obj) + sort_obj <=> other.sort_obj else super end @@ -51,6 +54,19 @@ module Bundler private + # Create a delegate used for sorting. This strategy is copied from + # RubyGems 2.23 and ensures that Bundler's specifications can be + # compared and sorted with RubyGems' own specifications. + # + # @see #<=> + # @see Gem::Specification#sort_obj + # + # @return [Array] an object you can use to compare and sort this + # specification against other specifications + def sort_obj + [@name, @version, @platform == Gem::Platform::RUBY ? -1 : 1] + end + def _remote_specification @_remote_specification ||= @spec_fetcher.fetch_spec([@name, @version, @platform]) end |