Class: Madeleine::SnapshotFile

Inherits:
NumberedFile show all
Defined in:
lib/madeleine.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NumberedFile

#name

Constructor Details

#initialize(directory_name, id) ⇒ SnapshotFile

Returns a new instance of SnapshotFile.



401
402
403
# File 'lib/madeleine.rb', line 401

def initialize(directory_name, id)
  super(directory_name, "snapshot", id)
end

Class Method Details

.highest_id(directory_name) ⇒ Object



382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/madeleine.rb', line 382

def self.highest_id(directory_name)
  return 0 unless File.exist?(directory_name)
  suffix = "snapshot"
  highest = 0
  Dir.foreach(directory_name) do |file_name|
    match = /^(\d{#{FILE_COUNTER_SIZE}}\.#{suffix}$)/.match(file_name)
    next unless match
    n = match[1].to_i
    if n > highest
      highest = n
    end
  end
  highest
end

.next(directory_name) ⇒ Object



397
398
399
# File 'lib/madeleine.rb', line 397

def self.next(directory_name)
  new(directory_name, highest_id(directory_name) + 1)
end