class Gem::RequestSet::GemDependencyAPI

A semi-compatible DSL for the Bundler Gemfile and Isolate formats.

Public Class Methods

new(set, path) click to toggle source

Creates a new GemDependencyAPI that will add dependencies to the Gem::RequestSet set based on the dependency API description in path.

# File lib/rubygems/request_set/gem_dependency_api.rb, line 134
def initialize set, path
  @set = set
  @path = path

  @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

Public Instance Methods

load() click to toggle source

Loads the gem dependency file

# File lib/rubygems/request_set/gem_dependency_api.rb, line 192
def load
  instance_eval File.read(@path).untaint, @path, 1
end

Private Instance Methods

pin_gem_source(name, type = :default, source = nil) click to toggle source

Pins the gem name to the given source. Adding a gem with the same name from a different source will raise an exception.

# File lib/rubygems/request_set/gem_dependency_api.rb, line 422
def pin_gem_source name, type = :default, source = nil
  source_description =
    case type
    when :default then '(default)'
    when :path    then "path: #{source}"
    when :git     then "git: #{source}"
    else               '(unknown)'
    end

  raise ArgumentError,
    "duplicate source #{source_description} for gem #{name}" if
      @gem_sources.fetch(name, source) != source

  @gem_sources[name] = source
end

Gem Dependencies DSL

↑ top

Public Instance Methods

gem(name) click to toggle source
gem(name, *requirements)
gem(name, *requirements, options)

Specifies a gem dependency with the given name and requirements. You may also supply options following the requirements

# File lib/rubygems/request_set/gem_dependency_api.rb, line 206
def gem name, *requirements
  options = requirements.pop if requirements.last.kind_of?(Hash)
  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

  groups = gem_group name, options

  return unless (groups & @without_groups).empty?

  pin_gem_source name, :default unless source_set

  gem_requires name, options

  @set.gem name, *requirements
end
gemspec(options = {}) click to toggle source

Loads dependencies from a gemspec file.

# File lib/rubygems/request_set/gem_dependency_api.rb, line 387
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
git(repository) { || ... } click to toggle source

Block form for specifying gems from a git repository.

# File lib/rubygems/request_set/gem_dependency_api.rb, line 366
def git repository
  @current_repository = repository

  yield

ensure
  @current_repository = nil
end
group(*groups) { || ... } click to toggle source

Block form for placing a dependency in the given groups.

# File lib/rubygems/request_set/gem_dependency_api.rb, line 409
def group *groups
  @current_groups = groups

  yield

ensure
  @current_groups = nil
end
platform(what) { || ... } click to toggle source

Block form for restricting gems to a particular platform.

# File lib/rubygems/request_set/gem_dependency_api.rb, line 445
def platform what
  @current_platform = what

  yield

ensure
  @current_platform = nil
end
Also aliased as: platforms
platforms(what)

Block form for restricting gems to a particular platform.

Alias for: platform
ruby(version, options = {}) click to toggle source

Restricts this gem dependencies file to the given ruby version. The :engine options from Bundler are currently ignored.

# File lib/rubygems/request_set/gem_dependency_api.rb, line 466
def ruby version, options = {}
  engine         = options[:engine]
  engine_version = options[:engine_version]

  raise ArgumentError,
        'you must specify engine_version along with the ruby engine' if
          engine and not engine_version

  unless RUBY_VERSION == version then
    message = "Your Ruby version is #{RUBY_VERSION}, " +
              "but your #{gem_deps_file} requires #{version}"

    raise Gem::RubyVersionMismatch, message
  end

  if engine and engine != Gem.ruby_engine then
    message = "Your ruby engine is #{Gem.ruby_engine}, " +
              "but your #{gem_deps_file} requires #{engine}"

    raise Gem::RubyVersionMismatch, message
  end

  if engine_version then
    my_engine_version = Object.const_get "#{Gem.ruby_engine.upcase}_VERSION"

    if engine_version != my_engine_version then
      message =
        "Your ruby engine version is #{Gem.ruby_engine} #{my_engine_version}, " +
        "but your #{gem_deps_file} requires #{engine} #{engine_version}"

      raise Gem::RubyVersionMismatch, message
    end
  end

  return true
end
source(url) click to toggle source

Sets url as a source for gems for this dependency API.

# File lib/rubygems/request_set/gem_dependency_api.rb, line 508
def source url
  Gem.sources.clear if @default_sources

  @default_sources = false

  Gem.sources << url
end