Class: CallerLog::Log

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

Defined Under Namespace

Classes: Html

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Log

Returns a new instance of Log.



12
13
14
15
16
17
# File 'lib/caller_log/log.rb', line 12

def initialize file
  file = File.new file, 'a+' unless File === file
  @file = file
  @html = Html.new
  @lock = Mutex.new
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



10
11
12
# File 'lib/caller_log/log.rb', line 10

def file
  @file
end

#htmlObject (readonly)

Returns the value of attribute html.



10
11
12
# File 'lib/caller_log/log.rb', line 10

def html
  @html
end

#lockObject (readonly)

Returns the value of attribute lock.



10
11
12
# File 'lib/caller_log/log.rb', line 10

def lock
  @lock
end

Instance Method Details

#puts(record) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/caller_log/log.rb', line 19

def puts record
  lock.synchronize do
    html.add record
    File.open file, 'w+' do |f|
      f.puts html.to_s
    end
  end
end