Class: Drydocker::Monitor

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

Overview

Class to actually run the monitor and tests

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Monitor

Returns a new instance of Monitor.



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

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#clean_containersObject



58
59
60
61
62
63
64
# File 'lib/drydocker.rb', line 58

def clean_containers
  fail "No docker found" if File.which("docker").nil?
  return unless system(docker_check_cmd)
  config.logger.debug("cleaning up previous containers")
  `docker kill #{config.name}`
  `docker rm #{config.name}`
end

#listenObject



48
49
50
51
52
53
54
55
56
# File 'lib/drydocker.rb', line 48

def listen
  run_or_start
  listener = Listen.to(config.path) do |modified, added, removed|
    config.logger.info("triggering change: #{modified + added + removed}")
    run_or_start
  end
  listener.start # not blocking
  config.logger.info("now listening")
end

#run_or_startObject



66
67
68
# File 'lib/drydocker.rb', line 66

def run_or_start
  system(docker_check_cmd) ? start : run
end