Class: DevDock::DevVolume

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

Overview

Volume which is needed for the development environment

Instance Method Summary collapse

Constructor Details

#initialize(image_name, path) ⇒ DevVolume

Returns a new instance of DevVolume.



12
13
14
15
# File 'lib/dev_dock/volumes.rb', line 12

def initialize(image_name, path)
  @path = path
  @name = DevDock::Util::snake_case("dev_dock_#{image_name}#{path}")
end

Instance Method Details

#createObject

creates the volume if it does not exist



33
34
35
36
37
38
39
# File 'lib/dev_dock/volumes.rb', line 33

def create
  Log::debug("Checking volume #{@name} for path #{@path}")
  if !exist?
    Log::info("Creating volume #{@name}")
    Docker::Volume.create(@name)
  end
end

#exist?Boolean

returns true if the volume exists

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/dev_dock/volumes.rb', line 26

def exist?
  volumes = Docker::Util.parse_json(Docker.connection.get('/volumes'))["Volumes"]
  Log::debug("Volumes in docker: #{volumes}")
  not volumes.nil? and volumes.any? { |volume| volume['Name'] == @name }
end

#nameObject



17
18
19
# File 'lib/dev_dock/volumes.rb', line 17

def name
  @name
end

#pathObject



21
22
23
# File 'lib/dev_dock/volumes.rb', line 21

def path
  @path
end

#removeObject

removes the volume if it exists



42
43
44
45
46
47
48
# File 'lib/dev_dock/volumes.rb', line 42

def remove
  Log::debug("Checking volume #{@name} for path #{@path}")
  if exist?
    Log::info("Removing volume #{@name})")
    Docker::Volume.get(@name).remove
  end
end