Class: Nanoc::Int::TempFilenameFactory Private
- Inherits:
-
Object
- Object
- Nanoc::Int::TempFilenameFactory
- Defined in:
- lib/nanoc/base/services/temp_filename_factory.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
-
#root_dir ⇒ String
readonly
private
The root directory for all temporary filenames.
Class Method Summary collapse
-
.instance ⇒ Nanoc::Int::TempFilenameFactory
private
A common instance.
Instance Method Summary collapse
- #cleanup(prefix) ⇒ void private
-
#create(prefix) ⇒ String
private
A new unused filename.
-
#initialize ⇒ TempFilenameFactory
constructor
private
A new instance of TempFilenameFactory.
Constructor Details
#initialize ⇒ TempFilenameFactory
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TempFilenameFactory.
14 15 16 17 |
# File 'lib/nanoc/base/services/temp_filename_factory.rb', line 14 def initialize @counts = {} @root_dir = Dir.mktmpdir('nanoc') end |
Instance Attribute Details
#root_dir ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The root directory for all temporary filenames.
7 8 9 |
# File 'lib/nanoc/base/services/temp_filename_factory.rb', line 7 def root_dir @root_dir end |
Class Method Details
.instance ⇒ Nanoc::Int::TempFilenameFactory
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns A common instance.
10 11 12 |
# File 'lib/nanoc/base/services/temp_filename_factory.rb', line 10 def self.instance @instance ||= new end |
Instance Method Details
#cleanup(prefix) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nanoc/base/services/temp_filename_factory.rb', line 39 def cleanup(prefix) path = File.join(@root_dir, prefix) if File.exist?(path) FileUtils.rm_rf(path) end @counts.delete(prefix) if @counts.empty? && File.directory?(@root_dir) FileUtils.rm_rf(@root_dir) end end |
#create(prefix) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns A new unused filename.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/nanoc/base/services/temp_filename_factory.rb', line 23 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 |