Sha256: 78e55073ef2758bdded999e8d6ac51096cacf0c5e456ef62c93656074f1458cb

Contents?: true

Size: 1.59 KB

Versions: 25

Compression:

Stored size: 1.59 KB

Contents

RSpec::Support.require_rspec_support 'os'

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::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

25 entries across 24 versions & 7 rubygems

Version Path
opal-rspec-0.8.0 rspec-support/upstream/lib/rspec/support/directory_maker.rb
opal-rspec-0.8.0.alpha3 rspec-support/upstream/lib/rspec/support/directory_maker.rb
opal-rspec-0.8.0.alpha2 rspec-support/upstream/lib/rspec/support/directory_maker.rb
opal-rspec-0.8.0.alpha1 rspec-support/upstream/lib/rspec/support/directory_maker.rb
opal-rspec-0.7.1 rspec-support/upstream/lib/rspec/support/directory_maker.rb
opal-rspec-0.7.0 rspec-support/upstream/lib/rspec/support/directory_maker.rb
opal-rspec-0.6.2 rspec-support/lib/rspec/support/directory_maker.rb
opal-rspec-0.7.0.rc.2 rspec-support/upstream/lib/rspec/support/directory_maker.rb
opal-rspec-0.6.1 rspec-support/lib/rspec/support/directory_maker.rb
opal-rspec-0.6.0 rspec-support/lib/rspec/support/directory_maker.rb
opal-rspec-0.6.0.beta1 rspec-support/lib/rspec/support/directory_maker.rb
opal-connect-rspec-0.5.0 rspec-support/lib/rspec/support/directory_maker.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/rspec-support-3.1.2/lib/rspec/support/directory_maker.rb
opal-rspec-0.5.0 rspec-support/lib/rspec/support/directory_maker.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/rspec-support-3.1.2/lib/rspec/support/directory_maker.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/rspec-support-3.1.2/lib/rspec/support/directory_maker.rb
logstash-codec-json-2.0.3 vendor/gems/rspec-support-3.1.2/lib/rspec/support/directory_maker.rb
opal-rspec-0.5.0.beta3 rspec-support/lib/rspec/support/directory_maker.rb
logstash-input-beats-0.9.2 vendor/jruby/1.9/gems/rspec-support-3.1.2/lib/rspec/support/directory_maker.rb
logstash-input-beats-0.9.1 vendor/jruby/1.9/gems/rspec-support-3.1.2/lib/rspec/support/directory_maker.rb