Sha256: 72e9f6f17f8172fe8078b7d279c1e02fd175fa377fe79a8dc334b4eabee32677

Contents?: true

Size: 827 Bytes

Versions: 33

Compression:

Stored size: 827 Bytes

Contents

# frozen_string_literal: true
require 'parallel_tests'

module ParallelTests
  module Gherkin
    module Io
      def prepare_io(path_or_io)
        if path_or_io.respond_to?(:write)
          path_or_io
        else # its a path
          File.open(path_or_io, 'w').close # clean out the file
          file = File.open(path_or_io, 'a')

          at_exit do
            unless file.closed?
              file.flush
              file.close
            end
          end

          file
        end
      end

      # do not let multiple processes get in each others way
      def lock_output
        if @io.is_a?(File)
          begin
            @io.flock File::LOCK_EX
            yield
          ensure
            @io.flock File::LOCK_UN
          end
        else
          yield
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
parallel_tests-4.7.2 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.7.1 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.7.0 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.6.1 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.6.0 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.5.2 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.5.1 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.5.0 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.4.0 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.3.0 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.2.2 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.2.1 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.2.0 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.1.0 lib/parallel_tests/gherkin/io.rb
parallel_tests-4.0.0 lib/parallel_tests/gherkin/io.rb
parallel_tests-3.13.0 lib/parallel_tests/gherkin/io.rb
parallel_tests-3.12.1 lib/parallel_tests/gherkin/io.rb
parallel_tests-3.12.0 lib/parallel_tests/gherkin/io.rb
parallel_tests-3.11.1 lib/parallel_tests/gherkin/io.rb
parallel_tests-3.11.0 lib/parallel_tests/gherkin/io.rb