Class: RSpec::Support::DirectoryMaker Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rspec-support/lib/rspec/support/directory_maker.rb |
Overview
Replacement for fileutils#mkdir_p because we don’t want to require parts of stdlib in ::RSpec
.
Class Method Summary
-
.mkdir_p(path)
Internal use only
Implements nested directory construction.
- .directory_exists?(dirname) ⇒ Boolean private Internal use only
-
.generate_path(stack, part)
private
See additional method definition at line 39.
-
.generate_stack(path)
private
See additional method definition at line 30.
Class Method Details
.directory_exists?(dirname) ⇒ Boolean
(private)
# File 'rspec-support/lib/rspec/support/directory_maker.rb', line 57
def self.directory_exists?(dirname) File.exist?(dirname) && File.directory?(dirname) end
.generate_path(stack, part) (private)
See additional method definition at line 39.
# File 'rspec-support/lib/rspec/support/directory_maker.rb', line 52
def self.generate_path(stack, part) if stack == '' part elsif stack == File::SEPARATOR File.join('', part) else File.join(stack, part) end end
.generate_stack(path) (private)
See additional method definition at line 30.
# File 'rspec-support/lib/rspec/support/directory_maker.rb', line 49
def self.generate_stack(path) if path.start_with?(File::SEPARATOR) File::SEPARATOR elsif path[1] == ':' '' else '.' end end
.mkdir_p(path)
Implements nested directory construction
# File 'rspec-support/lib/rspec/support/directory_maker.rb', line 15
def self.mkdir_p(path) stack = generate_stack(path) path.split(File::SEPARATOR).each do |part| stack = generate_path(stack, part) begin Dir.mkdir(stack) unless directory_exists?(stack) rescue Errno::EEXIST => e raise e unless directory_exists?(stack) rescue Errno::ENOTDIR => e raise Errno::EEXIST, e. end end end