Class: Kodama::Client::PositionFile

Inherits:
Object
  • Object
show all
Defined in:
lib/kodama/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ PositionFile

Returns a new instance of PositionFile.



225
226
227
228
# File 'lib/kodama/client.rb', line 225

def initialize(filename)
  @file = open(filename, File::RDWR|File::CREAT)
  @file.sync = true
end

Instance Method Details

#readObject



236
237
238
239
240
241
242
# File 'lib/kodama/client.rb', line 236

def read
  @file.pos = 0
  if line = @file.gets
    filename, position = line.split("\t")
    [filename, position.to_i]
  end
end

#update(filename, position) ⇒ Object



230
231
232
233
234
# File 'lib/kodama/client.rb', line 230

def update(filename, position)
  @file.pos = 0
  @file.write "#{filename}\t#{position}"
  @file.truncate @file.pos
end