diff options
Diffstat (limited to 'lib/rubygems/request_set/gem_dependency_api.rb')
-rw-r--r-- | lib/rubygems/request_set/gem_dependency_api.rb | 149 |
1 files changed, 141 insertions, 8 deletions
diff --git a/lib/rubygems/request_set/gem_dependency_api.rb b/lib/rubygems/request_set/gem_dependency_api.rb index e8f3138990..8e29eb87e5 100644 --- a/lib/rubygems/request_set/gem_dependency_api.rb +++ b/lib/rubygems/request_set/gem_dependency_api.rb @@ -108,6 +108,11 @@ class Gem::RequestSet::GemDependencyAPI } ## + # A set of gems that are loaded via the +:git+ option to #gem + + attr_reader :git_set # :nodoc: + + ## # A Hash containing gem names and files to require from those gems. attr_reader :requires @@ -130,13 +135,55 @@ class Gem::RequestSet::GemDependencyAPI @set = set @path = path - @current_groups = nil - @current_platform = nil - @default_sources = true - @requires = Hash.new { |h, name| h[name] = [] } - @vendor_set = @set.vendor_set - @gem_sources = {} - @without_groups = [] + @current_groups = nil + @current_platform = nil + @current_repository = nil + @default_sources = true + @git_set = @set.git_set + @requires = Hash.new { |h, name| h[name] = [] } + @vendor_set = @set.vendor_set + @gem_sources = {} + @without_groups = [] + end + + ## + # Adds +dependencies+ to the request set if any of the +groups+ are allowed. + # This is used for gemspec dependencies. + + def add_dependencies groups, dependencies # :nodoc: + return unless (groups & @without_groups).empty? + + dependencies.each do |dep| + @set.gem dep.name, *dep.requirement + end + end + + private :add_dependencies + + ## + # Finds a gemspec with the given +name+ that lives at +path+. + + def find_gemspec name, path # :nodoc: + glob = File.join path, "#{name}.gemspec" + + spec_files = Dir[glob] + + case spec_files.length + when 1 then + spec_file = spec_files.first + + spec = Gem::Specification.load spec_file + + return spec if spec + + raise ArgumentError, "invalid gemspec #{spec_file}" + when 0 then + raise ArgumentError, "no gemspecs found at #{Dir.pwd}" + else + raise ArgumentError, + "found multiple gemspecs at #{Dir.pwd}, " + + "use the name: option to specify the one you want" + end end ## @@ -160,7 +207,13 @@ class Gem::RequestSet::GemDependencyAPI options = requirements.pop if requirements.last.kind_of?(Hash) options ||= {} - source_set = gem_path name, options + options[:git] = @current_repository if @current_repository + + source_set = false + + source_set ||= gem_path name, options + source_set ||= gem_git name, options + source_set ||= gem_github name, options return unless gem_platforms options @@ -182,6 +235,54 @@ class Gem::RequestSet::GemDependencyAPI end ## + # Handles the git: option from +options+ for gem +name+. + # + # Returns +true+ if the path option was handled. + + def gem_git name, options # :nodoc: + if gist = options.delete(:gist) then + options[:git] = "https://gist.github.com/#{gist}.git" + end + + return unless repository = options.delete(:git) + + raise ArgumentError, + "duplicate source git: #{repository} for gem #{name}" if + @gem_sources.include? name + + reference = nil + reference ||= options.delete :ref + reference ||= options.delete :branch + reference ||= options.delete :tag + reference ||= 'master' + + submodules = options.delete :submodules + + @git_set.add_git_gem name, repository, reference, submodules + + @gem_sources[name] = repository + + true + end + + private :gem_git + + ## + # Handles the github: option from +options+ for gem +name+. + # + # Returns +true+ if the path option was handled. + + def gem_github name, options # :nodoc: + return unless path = options.delete(:github) + + options[:git] = "git://github.com/#{path}.git" + + gem_git name, options + + true + end + + ## # Handles the :group and :groups +options+ for the gem with the given # +name+. @@ -269,6 +370,15 @@ class Gem::RequestSet::GemDependencyAPI private :gem_requires + def git repository + @current_repository = repository + + yield + + ensure + @current_repository = nil + end + ## # Returns the basename of the file the dependencies were loaded from @@ -278,6 +388,29 @@ class Gem::RequestSet::GemDependencyAPI ## # :category: Gem Dependencies DSL + # + # Loads dependencies from a gemspec file. + + def gemspec options = {} + name = options.delete(:name) || '{,*}' + path = options.delete(:path) || '.' + development_group = options.delete(:development_group) || :development + + spec = find_gemspec name, path + + groups = gem_group spec.name, {} + + add_dependencies groups, spec.runtime_dependencies + + groups << development_group + + add_dependencies groups, spec.development_dependencies + + gem_requires spec.name, options + end + + ## + # :category: Gem Dependencies DSL # Block form for placing a dependency in the given +groups+. def group *groups |