Module: Kryten::Runner

Included in:
Task
Defined in:
lib/kryten/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#runningObject (readonly)

Returns the value of attribute running.



3
4
5
# File 'lib/kryten/runner.rb', line 3

def running
  @running
end

#startedObject (readonly)

Returns the value of attribute started.



3
4
5
# File 'lib/kryten/runner.rb', line 3

def started
  @started
end

#timerObject

Returns the value of attribute timer.



2
3
4
# File 'lib/kryten/runner.rb', line 2

def timer
  @timer
end

Instance Method Details

#debugObject



45
46
47
48
49
50
51
52
# File 'lib/kryten/runner.rb', line 45

def debug
  log "debugging"
  setup
  2.times do
    run
    sleep timer
  end
end

#initialize(title = nil) ⇒ Object



5
6
7
8
# File 'lib/kryten/runner.rb', line 5

def initialize title=nil
  @name, @running, @started = title, false, false
  Signal.trap("INT", proc { stop_running })
end

#log(message) ⇒ Object



54
55
56
# File 'lib/kryten/runner.rb', line 54

def log message
  puts [name, message].join(': ')
end

#nameObject



58
59
60
# File 'lib/kryten/runner.rb', line 58

def name
  @name || self.class.to_s.gsub('::','-').downcase
end

#runObject



29
30
31
# File 'lib/kryten/runner.rb', line 29

def run
  log "running"
end

#setupObject



41
42
43
# File 'lib/kryten/runner.rb', line 41

def setup
  log "setting up"
end

#startObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kryten/runner.rb', line 10

def start
  setup
  log "starting"
  @started = true

  while started do
    sleep timer
    @running = true
    run
    @running = false
  end

  log "stopped"
  true
rescue => e
  log "error #{e}"
  #raise
end

#statusObject



62
63
64
65
66
# File 'lib/kryten/runner.rb', line 62

def status
  log [started ? 'on and ' : 'off and ',
       running ? 'running' : 'sleeping'].join
  started
end

#stop_runningObject



37
38
39
# File 'lib/kryten/runner.rb', line 37

def stop_running
  @started = false
end