Class: Drydock::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.



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

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



32
33
34
# File 'lib/drydocker.rb', line 32

def config
  @config
end

Instance Method Details

#clean_containersObject



46
47
48
49
50
51
# File 'lib/drydocker.rb', line 46

def clean_containers
  fail 'No docker found' if File.which('docker').nil?
  return unless system("docker ps | grep #{config.name}")
  `docker kill #{config.name}`
  `docker rm #{config.name}`
end

#listenObject



38
39
40
41
42
43
44
# File 'lib/drydocker.rb', line 38

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