Class: Called::LogFile
- Inherits:
-
Object
- Object
- Called::LogFile
- Defined in:
- lib/called.rb
Instance Method Summary collapse
- #format(set) ⇒ Object
-
#initialize(path) ⇒ LogFile
constructor
A new instance of LogFile.
- #puts(record) ⇒ Object
Constructor Details
#initialize(path) ⇒ LogFile
Returns a new instance of LogFile.
32 33 34 35 36 |
# File 'lib/called.rb', line 32 def initialize path @lock = Mutex.new @set = Set.new @path = path end |
Instance Method Details
#format(set) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/called.rb', line 47 def format set records= set.to_a max_len = records. max{|rec| rec.method_name.length}. method_name. length + 1 records.map do |rec| formatted = "%#{max_len}s" % rec.method_name "#{formatted} | #{rec.called_from}" end.join "\n" end |
#puts(record) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/called.rb', line 38 def puts record @lock.synchronize do @set << record File.open @path, 'w' do |f| f.puts format @set end end end |