Class: DevDock::DevBind

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_dock/binds.rb

Overview

binds are a type of mount which just map what is on the host into the container

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(internal_volumes, source, target, permissions) ⇒ DevBind

Returns a new instance of DevBind.



11
12
13
14
15
16
# File 'lib/dev_dock/binds.rb', line 11

def initialize(internal_volumes, source, target, permissions)
  @internal_volumes = internal_volumes
  @source = source
  @target = target
  @permissions = permissions
end

Instance Attribute Details

#permissionsObject (readonly)

Returns the value of attribute permissions.



9
10
11
# File 'lib/dev_dock/binds.rb', line 9

def permissions
  @permissions
end

#sourceObject (readonly)

Returns the value of attribute source.



9
10
11
# File 'lib/dev_dock/binds.rb', line 9

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



9
10
11
# File 'lib/dev_dock/binds.rb', line 9

def target
  @target
end

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/dev_dock/binds.rb', line 22

def create
  if not exist?
    if not File.directory?(@source)
      FileUtils.mkdir_p(File.dirname(@source))
      FileUtils.touch(@source)
    else
      FileUtils.mkdir_p(@source)
    end
  end
end

#exist?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/dev_dock/binds.rb', line 18

def exist?
  File.exist?(@source)
end

#host_pathObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dev_dock/binds.rb', line 33

def host_path
  if @internal_volumes
    internal, host = parent_volume
    # just need to take out the part of the path which is internal, and
    # replace it with the host volume.
    relative = @source.slice(internal.length, @source.length)
    if relative.length == 0
      host
    else
      File.join(host, relative)
    end
  else
    @source
  end
end

#parent_volumeObject



49
50
51
# File 'lib/dev_dock/binds.rb', line 49

def parent_volume
  @internal_volumes.find { |internal, host| @source.index(internal) == 0 }
end

#to_argumentObject



53
54
55
# File 'lib/dev_dock/binds.rb', line 53

def to_argument
  [host_path, @target, @permissions].compact.join(':')
end