Class: Maildir::UniqueName

Inherits:
Object
  • Object
show all
Defined in:
lib/maildir/unique_name.rb

Overview

Class for generating unique file names for new messages

Constant Summary collapse

COUNTER_MUTEX =
Mutex.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUniqueName

Return a unique file name based on strategy



23
24
25
26
# File 'lib/maildir/unique_name.rb', line 23

def initialize
  # Use the same time object
  @now = Time.now
end

Class Method Details

.counterObject

Return a thread-safe increasing counter



10
11
12
13
14
15
# File 'lib/maildir/unique_name.rb', line 10

def counter
  COUNTER_MUTEX.synchronize do
    @counter ||= 0
    @counter = @counter.to_i.succ
  end
end

.createObject



17
18
19
# File 'lib/maildir/unique_name.rb', line 17

def create
  self.new.to_s
end

Instance Method Details

#to_sObject

Return the name as a string



29
30
31
# File 'lib/maildir/unique_name.rb', line 29

def to_s
  [left, middle, right].join(".")
end