Class: Bundler::CommonGemfile

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler-common_gemfile.rb

Class Method Summary collapse

Class Method Details

.load_other(context) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/bundler-common_gemfile.rb', line 34

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_remote', true) # allow git commands

      gem_path = if source.respond_to?('install_path')
                   source.install_path # remote gem
                 else
                   source.expanded_original_path # local gem
                 end
      source.instance_variable_set('@install_path', nil) # unset

      if !File.exist?(gem_path) && source.is_a?(::Bundler::Source::Git)
        puts "Fetching #{source.name.to_s.green.bold} in search of common-gemfile"
        source.specs
      end

      gemfile_common_path = gem_path.join('Gemfile-common.rb')
      if !evaled.include?(gemfile_common_path) && File.exist?(gemfile_common_path)
        evaled << gemfile_common_path
        STDERR.puts "Loading #{gemfile_common_path.to_s.green.bold}"
        content = File.read(gemfile_common_path)
        $stderr.puts content if ENV['DEBUG_GEMFILE_COMMON']
        context.send(:eval, content)
        $stderr.puts 'ok'.green.bold
      end
    end

    break if evaled.size == number_of_evaled
  end
end