Class: Pmux::Joblogger

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, job) ⇒ Joblogger

Returns a new instance of Joblogger.



7
8
9
10
11
12
13
14
# File 'lib/pmux/joblogger.rb', line 7

def initialize dir, job
  @dir = dir
  @job = job
  if dir and File.directory? dir
    @path = "#{dir}/#{job.id}.yml"
    @f = open(@path, 'w')
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/pmux/joblogger.rb', line 5

def path
  @path
end

Instance Method Details

#add(key, obj) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/pmux/joblogger.rb', line 34

def add key, obj
  return unless @f
  @f.puts "#{key}:"
  for k, v in obj
    @f.puts "  #{k}: #{v.inspect}"
  end
end

#closeObject



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

def close
  @f.close if @f
end

#dump(obj) ⇒ Object



24
25
26
# File 'lib/pmux/joblogger.rb', line 24

def dump obj
  @f.print YAML.dump(obj) if @f
end


20
21
22
# File 'lib/pmux/joblogger.rb', line 20

def dump_footer
  dump @job.to_jlfooter
end

#dump_headerObject



16
17
18
# File 'lib/pmux/joblogger.rb', line 16

def dump_header
  dump @job.to_jlheader
end

#sepObject



28
29
30
31
32
# File 'lib/pmux/joblogger.rb', line 28

def sep
  return unless @f
  @f.puts '---'
  @f.flush
end