Class: Dockerun::Config

Inherits:
Object
  • Object
show all
Includes:
TR::CondUtils
Defined in:
lib/dockerun/config.rb

Constant Summary collapse

FILENAME =
".dockerun".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configHash = { }, configFileAvail = false) ⇒ Config

Returns a new instance of Config.



29
30
31
32
33
34
# File 'lib/dockerun/config.rb', line 29

def initialize(configHash = {  }, configFileAvail = false)
  @config = configHash 
  @images = @config[:images]
  @confFileAvail = configFileAvail
  @images = {  } if @images.nil?
end

Class Method Details

.from_storageObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dockerun/config.rb', line 10

def self.from_storage
  path = File.join(Dir.getwd, FILENAME)
  if File.exist?(path)
    cont = nil
    File.open(path,"r") do |f|
      cont = f.read
    end

    Config.new(YAML.load(cont), true)
  else
    Config.new({}, false)
  end
end

.removeObject



24
25
26
27
# File 'lib/dockerun/config.rb', line 24

def self.remove
  path = File.join(Dir.getwd, FILENAME)
  FileUtils.rm(path) if File.exist?(path)
end

Instance Method Details

#add_container(imageName, name) ⇒ Object



60
61
62
63
# File 'lib/dockerun/config.rb', line 60

def add_container(imageName, name)
  @images[imageName] = {  } if @images[imageName].nil?
  @images[imageName][name] = {} if @images[imageName][name].nil?
end

#add_image(name) ⇒ Object



44
45
46
# File 'lib/dockerun/config.rb', line 44

def add_image(name)
  @images[name] = {  } if not_empty?(name) and not @images.keys.include?(name)
end

#add_mount_to_container(imageName, container, mount) ⇒ Object



71
72
73
74
75
# File 'lib/dockerun/config.rb', line 71

def add_mount_to_container(imageName, container, mount)
  add_container(imageName, container)
  @images[imageName][container][:mount] = [] if @images[imageName][container][:mount].nil?
  @images[imageName][container][:mount] << mount
end

#container_configs(imageName, name) ⇒ Object



56
57
58
# File 'lib/dockerun/config.rb', line 56

def container_configs(imageName, name)
  @images[imageName].nil? ? {} : @images[imageName][name].nil? ? {} : @images[imageName][name]
end

#container_names(imageName) ⇒ Object



52
53
54
# File 'lib/dockerun/config.rb', line 52

def container_names(imageName)
  @images[imageName].keys
end

#image_namesObject



40
41
42
# File 'lib/dockerun/config.rb', line 40

def image_names
  @images.keys
end

#isConfigFileAvail?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/dockerun/config.rb', line 36

def isConfigFileAvail?
  @confFileAvail
end

#mount_of_container(container) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/dockerun/config.rb', line 77

def mount_of_container(container)
  res = @containers[container]
  if is_empty?(res) or is_empty?(res[:mount])
    []
  else
    res[:mount]
  end
end

#remove_container(imageName, name) ⇒ Object



65
66
67
68
69
# File 'lib/dockerun/config.rb', line 65

def remove_container(imageName, name)
  if not @images[imageName].nil?
    @images[imageName].delete(name) 
  end
end

#remove_image(name) ⇒ Object



48
49
50
# File 'lib/dockerun/config.rb', line 48

def remove_image(name)
  @images.delete(name)
end

#to_storageObject Also known as: save



86
87
88
89
90
91
92
93
# File 'lib/dockerun/config.rb', line 86

def to_storage
  res = { images: @images } 

  path = File.join(Dir.getwd, FILENAME)
  File.open(path,"w") do |f|
    f.write YAML.dump(res)
  end
end