Sha256: a730538c084a43c3fa63d3be077bc0f4ea125419efc2312e51a4acf1a154ded7

Contents?: true

Size: 1.69 KB

Versions: 5328

Compression:

Stored size: 1.69 KB

Contents

RSpec::Support.require_rspec_support 'ruby_features'

module RSpec
  module Support
    # @api private
    #
    # Replacement for fileutils#mkdir_p because we don't want to require parts
    # of stdlib in RSpec.
    class DirectoryMaker
      # @api private
      #
      # Implements nested directory construction
      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.message
          end
        end
      end

      if OS.windows_file_path?
        def self.generate_stack(path)
          if path.start_with?(File::SEPARATOR)
            File::SEPARATOR
          elsif path[1] == ':'
            ''
          else
            '.'
          end
        end
        def self.generate_path(stack, part)
          if stack == ''
            part
          elsif stack == File::SEPARATOR
            File.join('', part)
          else
            File.join(stack, part)
          end
        end
      else
        def self.generate_stack(path)
          path.start_with?(File::SEPARATOR) ? File::SEPARATOR : "."
        end
        def self.generate_path(stack, part)
          File.join(stack, part)
        end
      end

      def self.directory_exists?(dirname)
        File.exist?(dirname) && File.directory?(dirname)
      end
      private_class_method :directory_exists?
      private_class_method :generate_stack
      private_class_method :generate_path
    end
  end
end

Version data entries

5,328 entries across 5,242 versions & 121 rubygems

Version Path
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/directory_maker.rb
mux_ruby-3.19.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/directory_maker.rb
moneykit-0.1.15 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/directory_maker.rb
moneykit-0.1.14 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/directory_maker.rb
mux_ruby-3.18.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/directory_maker.rb
moneykit-0.1.13 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/directory_maker.rb
moneykit-0.1.12 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/directory_maker.rb
moneykit-0.1.11 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/directory_maker.rb
mux_ruby-3.17.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/directory_maker.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.10.2/lib/rspec/support/directory_maker.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.10.2/lib/rspec/support/directory_maker.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.10.2/lib/rspec/support/directory_maker.rb
moneykit-0.1.10 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/directory_maker.rb
moneykit-0.1.9 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/directory_maker.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/directory_maker.rb
mux_ruby-3.15.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/directory_maker.rb
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/rspec-support-3.11.0/lib/rspec/support/directory_maker.rb
mux_ruby-3.14.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/directory_maker.rb
moneykit-0.1.6 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/directory_maker.rb
cybrid_api_id_ruby-0.113.118 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/directory_maker.rb