Class: Nanoc::TempFilenameFactory
- Inherits:
-
Object
- Object
- Nanoc::TempFilenameFactory
- Defined in:
- lib/nanoc/base/temp_filename_factory.rb
Instance Attribute Summary (collapse)
-
- (String) root_dir
readonly
The root directory for all temporary filenames.
Class Method Summary (collapse)
-
+ (Nanoc::TempFilenameFactory) instance
A common instance.
Instance Method Summary (collapse)
-
- (void) cleanup(prefix)
-
- (String) create(prefix)
A new unused filename.
-
- (TempFilenameFactory) initialize
constructor
A new instance of TempFilenameFactory.
Constructor Details
- (TempFilenameFactory) initialize
Returns a new instance of TempFilenameFactory
17 18 19 20 |
# File 'lib/nanoc/base/temp_filename_factory.rb', line 17 def initialize @counts = {} @root_dir = Dir.mktmpdir('nanoc') end |
Instance Attribute Details
- (String) root_dir (readonly)
Returns The root directory for all temporary filenames
10 11 12 |
# File 'lib/nanoc/base/temp_filename_factory.rb', line 10 def root_dir @root_dir end |
Class Method Details
+ (Nanoc::TempFilenameFactory) instance
Returns A common instance
13 14 15 |
# File 'lib/nanoc/base/temp_filename_factory.rb', line 13 def self.instance @instance ||= new end |
Instance Method Details
- (void) cleanup(prefix)
This method returns an undefined value.
42 43 44 45 46 47 48 49 |
# File 'lib/nanoc/base/temp_filename_factory.rb', line 42 def cleanup(prefix) path = File.join(@root_dir, prefix) if File.exist?(path) FileUtils.remove_entry_secure(path) end @counts.delete(prefix) end |
- (String) create(prefix)
Returns A new unused filename
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/nanoc/base/temp_filename_factory.rb', line 26 def create(prefix) count = @counts.fetch(prefix, 0) @counts[prefix] = count + 1 dirname = File.join(@root_dir, prefix) filename = File.join(@root_dir, prefix, count.to_s) FileUtils.mkdir_p(dirname) filename end |