diff options
author | Andre Arko <andre@arko.net> | 2013-07-17 22:53:55 +0000 |
---|---|---|
committer | Tim Moore <tmoore@incrementalism.net> | 2014-07-30 14:16:36 +1000 |
commit | a0e2c8dcbf94f0e8d52230e89f9be11f8c228c7d (patch) | |
tree | 415ba5135900edf9a1ce62ac6045bf7905401471 /lib/bundler | |
parent | 3f3ff6cdd3d1dff4b5278d2d975386915289d47c (diff) | |
download | bundler-a0e2c8dcbf94f0e8d52230e89f9be11f8c228c7d.tar.gz |
Separate Rubygems sources into multiple objects.
with @TimMoore and @ckrailo
Diffstat (limited to 'lib/bundler')
-rw-r--r-- | lib/bundler/definition.rb | 21 | ||||
-rw-r--r-- | lib/bundler/source.rb | 3 | ||||
-rw-r--r-- | lib/bundler/source/rubygems.rb | 19 | ||||
-rw-r--r-- | lib/bundler/source_list.rb | 41 |
4 files changed, 41 insertions, 43 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index b1ebba6e..f03e7e7f 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -226,12 +226,14 @@ module Bundler # spec, even if (say) a git gem is not checked out. def rubygems_index @rubygems_index ||= Index.build do |idx| - idx.add_source sources.rubygems_source.specs + sources.rubygems_sources.each do |rubygems| + idx.add_source rubygems.specs + end end end def has_rubygems_remotes? - sources.rubygems_source.remotes.any? + sources.rubygems_sources.any? {|s| s.remotes.any? } end def has_local_dependencies? @@ -271,12 +273,12 @@ module Bundler def to_lock out = "" - sources.all_sources.each do |source| + sources.lock_sources.each do |source| # Add the source header out << source.to_lock # Find all specs for this source resolve. - select { |s| s.source == source }. + select { |s| source.can_lock?(s) }. # This needs to be sorted by full name so that # gems with the same name, but different platform # are ordered consistently @@ -461,16 +463,7 @@ module Bundler changes = false # Get the Rubygems source from the Gemfile.lock - locked_gem = @locked_sources.find { |s| s.kind_of?(Source::Rubygems) } - - # Get the Rubygems source from the Gemfile - actual_gem = sources.rubygems_source - - # If there is a Rubygems source in both - if locked_gem && actual_gem - # Merge the remotes from the Gemfile into the Gemfile.lock - changes = changes | locked_gem.replace_remotes(actual_gem) - end + locked_gem = @locked_sources.select { |s| s.kind_of?(Source::Rubygems) } # Replace the sources from the Gemfile with the sources from the Gemfile.lock, # if they exist in the Gemfile.lock and are `==`. If you can't find an equivalent diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index a42bfde7..ce0cbb5d 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -24,5 +24,8 @@ module Bundler message end + def can_lock?(spec) + spec.source == self + end end end diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 203473ed..eb60a508 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -29,15 +29,19 @@ module Bundler end def hash - Rubygems.hash + @remotes.hash end def eql?(o) - o.is_a?(Rubygems) + o.is_a?(Rubygems) && remotes == o.remotes end alias == eql? + def can_lock?(spec) + spec.source.is_a?(Rubygems) + end + def options { "remotes" => @remotes.map { |r| r.to_s } } end @@ -158,17 +162,6 @@ module Bundler @remotes.unshift(uri) unless @remotes.include?(uri) end - def replace_remotes(source) - return false if source.remotes == @remotes - - @remotes = [] - source.remotes.each do |r| - add_remote r.to_s - end - - true - end - protected def source_uris_for_spec(spec) diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb index 6b794359..4f537c4a 100644 --- a/lib/bundler/source_list.rb +++ b/lib/bundler/source_list.rb @@ -2,12 +2,13 @@ module Bundler class SourceList attr_reader :path_sources, :git_sources, - :rubygems_source + :rubygems_sources def initialize - @path_sources = [] - @git_sources = [] - @rubygems_source = Source::Rubygems.new + @path_sources = [] + @git_sources = [] + @rubygems_aggregate = Source::Rubygems.new + @rubygems_sources = [@rubygems_aggregate] end def add_path_source(options = {}) @@ -18,30 +19,33 @@ module Bundler add_source_to_list Source::Git.new(options), git_sources end + def add_rubygems_source(options = {}) + add_source_to_list Source::Rubygems.new(options), @rubygems_sources + end + def add_rubygems_remote(uri) - @rubygems_source.add_remote(uri) - @rubygems_source + @rubygems_aggregate.add_remote(uri) + @rubygems_aggregate end def all_sources - path_sources + git_sources << rubygems_source + path_sources + git_sources + rubygems_sources end def get(source) - if source.is_a?(Source::Rubygems) - rubygems_source - else - source_list_for(source).find { |s| source == s } - end + source_list_for(source).find { |s| source == s } + end + + def lock_sources + (path_sources + git_sources) << combine_rubygems_sources end def replace_sources!(replacement_sources) - [path_sources, git_sources].each do |source_list| + [path_sources, git_sources, rubygems_sources].each do |source_list| source_list.map! do |source| replacement_sources.find { |s| s == source } || source end end - @rubygems_source = replacement_sources.find { |s| s == rubygems_source } || rubygems_source end def cached! @@ -61,10 +65,15 @@ module Bundler def source_list_for(source) case source - when Source::Git then git_sources - when Source::Path then path_sources + when Source::Git then git_sources + when Source::Path then path_sources + when Source::Rubygems then rubygems_sources else raise ArgumentError, "Invalid source: #{source.inspect}" end end + + def combine_rubygems_sources + Source::Rubygems.new("remotes" => rubygems_sources.map(&:remotes).flatten.uniq.reverse) + end end end |