Class: Maildir::UniqueName
- Inherits:
-
Object
- Object
- Maildir::UniqueName
- 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
-
.counter ⇒ Object
Return a thread-safe increasing counter.
- .create ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ UniqueName
constructor
Return a unique file name based on strategy.
-
#to_s ⇒ Object
Return the name as a string.
Constructor Details
#initialize ⇒ UniqueName
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
.counter ⇒ Object
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 |
.create ⇒ Object
17 18 19 |
# File 'lib/maildir/unique_name.rb', line 17 def create self.new.to_s end |
Instance Method Details
#to_s ⇒ Object
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 |