Sha256: bd7e05e336f7029b5d182b4fb457831a7035941890fe2cf5c531b078faef3d89

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

require 'appraisal/dependency'
require 'appraisal/gemspec'

module Appraisal
  # Load bundler Gemfiles and merge dependencies
  class Gemfile
    attr_reader :dependencies

    def initialize
      @sources = []
      @dependencies = []
    end

    def load(path)
      run(IO.read(path))
    end

    def run(definitions)
      instance_eval(definitions, __FILE__, __LINE__)
    end

    def gem(name, *requirements)
      @dependencies.reject! { |dependency| dependency.name == name }
      @dependencies << Dependency.new(name, requirements)
    end

    def group(*names)
      # ignore the group
    end

    def source(source)
      @sources << source
    end

    def to_s
      [source_entry, dependencies_entry, gemspec_entry].join("\n\n")
    end

    def dup
      gemfile = Gemfile.new
      @sources.each { |source| gemfile.source(source) }
      dependencies.each do |dependency|
        gemfile.gem(dependency.name, *dependency.requirements)
      end
      gemfile.gemspec(@gemspec.options) if @gemspec
      gemfile
    end

    def gemspec(options = {})
      @gemspec = Gemspec.new(options)
    end

    protected

    def source_entry
      @sources.map { |source| "source #{source.inspect}" }.join("\n")
    end

    def dependencies_entry
      dependencies.map { |dependency| dependency.to_s }.join("\n")
    end

    def gemspec_entry
      @gemspec.to_s
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/appraisal-0.5.1/lib/appraisal/gemfile.rb
appraisal-0.5.1 lib/appraisal/gemfile.rb
appraisal-0.5.0 lib/appraisal/gemfile.rb