Class: DockerProcess

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

Overview

GOAL: have object which is used to create and manage docker contains based around the idea that we treat them like procs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ DockerProcess

Returns a new instance of DockerProcess.



36
37
38
39
40
# File 'lib/docker_process.rb', line 36

def initialize config
  raise 'image not set' if self.class.image_name.nil?
  raise 'properties not set' if self.class.properties.empty?
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



34
35
36
# File 'lib/docker_process.rb', line 34

def config
  @config
end

Class Method Details

.image_nameObject



13
14
15
# File 'lib/docker_process.rb', line 13

def self.image_name
  @image_name
end

.propertiesObject



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

def self.properties
  @properties
end

.set_image_name(name) ⇒ Object



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

def self.set_image_name name
  @image_name = name
end

.set_properties(*new_properties) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/docker_process.rb', line 25

def self.set_properties *new_properties
  puts "setting properties: #{new_properties}"
  @properties ||= []
  raise 'can not reset properties' if !@properties.empty?
  new_properties.map(&:to_sym).each do |property|
    @properties << property
  end
end

Instance Method Details

#is_running?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
# File 'lib/docker_process.rb', line 50

def is_running?
  container = find_container
  if container
    container_is_running? container
  else
    false
  end
end

#recent_logsObject



59
60
61
# File 'lib/docker_process.rb', line 59

def recent_logs
  container_logs
end

#startObject



42
43
44
# File 'lib/docker_process.rb', line 42

def start
  start_container
end

#stopObject



46
47
48
# File 'lib/docker_process.rb', line 46

def stop
  kill_and_delete_container
end