class Bundler::CommonGemfile

Public Class Methods

load_other(context) click to toggle source
# File lib/bundler-common_gemfile.rb, line 3
def self.load_other(context)
  evaled = []

  while true
    number_of_evaled = evaled.size
    sources = context.instance_variable_get('@sources').all_sources
    sources.select { |s| s.is_a?(Bundler::Source::Git) || s.is_a?(Bundler::Source::Path) }.each do |source|

      source.instance_variable_set('@allow_cached', true)
      gem_path = if source.respond_to?('install_path')
                   source.install_path
                 else
                   source.expanded_original_path
                 end

      gemfile_common_path = gem_path.join('Gemfile-common.rb')

      if !File.exist?(gem_path) && source.is_a?(Bundler::Source::Git)
        STDERR.puts "  fetching \e[1m\e[92m#{source.name}\e[0m is search of common-gemfile"
        source.specs
      end
      if !evaled.include?(gemfile_common_path) && File.exist?(gemfile_common_path)
        evaled << gemfile_common_path
        STDERR.puts "Evaling \e[1m\e[92m#{gemfile_common_path}\e[0m"
        content = File.read(gemfile_common_path)
        STDERR.puts content if ENV['DEBUG_GEMFILE_COMMON']
        context.send(:eval, content)
        STDERR.puts "Evaling \e[1m\e[92m#{'done'}\e[0m"
      end
    end

    if evaled.size == number_of_evaled
      # root = context.send(:gemfile_root)
      # FileUtils.mkdir_p(root.join('.bundle'))
      # File.open(root.join('.bundle/Gemfile-common-gems'), 'w') { |f| f.write(evaled.sort.join(' '))}
      break
    end
  end
end