Class: Dockdev::Context::Rubygems

Inherits:
Object
  • Object
show all
Defined in:
lib/dockdev/context/rubygems.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Rubygems

Returns a new instance of Rubygems.



12
13
14
# File 'lib/dockdev/context/rubygems.rb', line 12

def initialize(path)
  @path = path
end

Class Method Details

.init_path(path) ⇒ Object



8
9
10
# File 'lib/dockdev/context/rubygems.rb', line 8

def self.init_path(path)
  Rubygems.new(path)
end

Instance Method Details

#find_gemfileObject



20
21
22
# File 'lib/dockdev/context/rubygems.rb', line 20

def find_gemfile
  Dir.glob(File.join(@path,"Gemfile"))
end

#is_context?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/dockdev/context/rubygems.rb', line 16

def is_context?
  find_gemfile.length > 0
end

#process_mount(mount_hash, dir_inside_docker = "/opt") ⇒ Object



24
25
26
27
28
29
30
31
32
33
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
# File 'lib/dockdev/context/rubygems.rb', line 24

def process_mount(mount_hash, dir_inside_docker = "/opt")

  if not mount_hash.nil? and mount_hash.is_a?(Hash)

    script = ["#!/bin/bash"]
    #script << "alias be > /dev/null 2>&1 && echo 'alias be=bundle exec' >> ~/.bashrc"
    script << "echo 'alias be=\"bundle exec\"' >> ~/.bashrc"

    # 
    # looking at source code 
    # https://github.com/rubygems/rubygems/blob/master/bundler/lib/bundler/shared_helpers.rb#L246
    # seems this is the way to set root for Bundler
    #
    ENV['BUNDLE_GEMFILE'] = find_gemfile.first
    Bundler.load.dependencies.each do |d|
      if not d.source.nil?
        src = d.source
        if src.path.to_s != "."
          pathInsideDocker = File.join(dir_inside_docker, d.name)
          mount_hash[src.path.expand_path.to_s] = pathInsideDocker
          script << "bundle config --global local.#{d.name} #{pathInsideDocker}"
          #res[d.name] = src.path.expand_path.to_s
        end
      end
    end

    scriptOut = File.join(@path,"to-be-executed-once-inside-docker.sh") 
    File.open(scriptOut,"w") do |f|
      f.write script.join("\n")
    end
    `chmod +x #{scriptOut}`

  end

  mount_hash
end