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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUniqueName

Return a unique file name based on strategy



20
21
22
23
# File 'lib/maildir/unique_name.rb', line 20

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

Class Method Details

.counterObject

Return a thread-safe increasing counter



7
8
9
10
11
12
# File 'lib/maildir/unique_name.rb', line 7

def counter
  @counter_mutex ||= Mutex.new
  @counter_mutex.synchronize do
    @counter = @counter.to_i + 1
  end
end

.createObject



14
15
16
# File 'lib/maildir/unique_name.rb', line 14

def create
  self.new.to_s
end

Instance Method Details

#to_sObject

Return the name as a string



26
27
28
# File 'lib/maildir/unique_name.rb', line 26

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