diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index f8d9784..c2f68c6 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -15,7 +15,6 @@ module Rails @requirement = Gem::Requirement.create(options[:version]) end - @version = @requirement.instance_variable_get("@requirements").first.last if @requirement @name = name.to_s @lib = options[:lib] @source = options[:source] @@ -24,26 +23,40 @@ module Rails end def unpacked_paths - Dir[File.join(self.class.unpacked_path, "#{@name}-#{@version || "*"}")] + Dir[File.join(self.class.unpacked_path, "#{@name}-*")] end def add_load_paths return if @loaded || @load_paths_added unpacked_paths = self.unpacked_paths - if unpacked_paths.empty? + + if @requirement.nil? + unpacked_path_matching_version = unpacked_paths.first + else + unpacked_path_matching_version = unpacked_paths.select do |path| + path_matches_version_requirement?(path) + end.first + end + + if unpacked_path_matching_version.nil? args = [@name] args << @requirement.to_s if @requirement gem *args else - $LOAD_PATH.unshift File.join(unpacked_paths.first, 'lib') - ext = File.join(unpacked_paths.first, 'ext') + $LOAD_PATH.unshift File.join(unpacked_path_matching_version, 'lib') + ext = File.join(unpacked_path_matching_version, 'ext') $LOAD_PATH.unshift(ext) if File.exist?(ext) @frozen = true end @load_paths_added = true rescue Gem::LoadError end - + + def path_matches_version_requirement?(path) + return unless path_version = path.match(/#{@name}\-(\d(\d|\.)*)/)[1] + @requirement.satisfied_by?(Gem::Version.create(path_version)) + end + def dependencies all_dependencies = specification.dependencies.map do |dependency| GemDependency.new(dependency.name, :requirement => dependency.version_requirements)