Class: Dike::LogFactory

Inherits:
Object show all
Defined in:
lib/dike.rb

Instance Method Summary collapse

Constructor Details

#initialize(directory = "dike") ⇒ LogFactory

Returns a new instance of LogFactory.



10
11
12
13
14
15
16
17
# File 'lib/dike.rb', line 10

def initialize directory = "dike"
  require "fileutils"
  FileUtils.mkdir_p directory
  @directory = directory
  list = Dir.glob(File.join(@directory, "*"))
  list = list.grep(%r/^[0-9]+$/).map{|entry| entry.to_i}
  @current = list.max || -1 
end

Instance Method Details

#next(&block) ⇒ Object



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

def next &block
  if block
    open File.join(@directory, self.next.to_s), "w", &block 
  else
    @current += 1
  end
end