Sha256: 9c83feebd805ad66e63968634313bd6ea2bc1e8b7db23bb2c9d0a688718cf7ca

Contents?: true

Size: 985 Bytes

Versions: 48

Compression:

Stored size: 985 Bytes

Contents

# frozen_string_literal: true

require 'tempfile'

module Dsu
  module Services
    module TempFile
      class WriterService
        def initialize(tmp_file_content:, options: {})
          raise ArgumentError, 'tmp_file_content is nil' if tmp_file_content.nil?
          raise ArgumentError, 'tmp_file_content is the wrong object type' unless tmp_file_content.is_a?(String)
          raise ArgumentError, 'options is nil' if options.nil?
          raise ArgumentError, 'options is the wrong object type' unless options.is_a?(Hash)

          @tmp_file_content = tmp_file_content
          @options = options || {}
        end

        def call
          raise ArgumentError, 'no block given' unless block_given?

          Tempfile.new('dsu').tap do |file|
            file.write("#{tmp_file_content}\n")
            file.close
            yield file.path
          end.unlink
        end

        private

        attr_reader :tmp_file_content, :options
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
dsu-3.0.0.alpha.1 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.0 lib/dsu/services/temp_file/writer_service.rb
dsu-2.4.4 lib/dsu/services/temp_file/writer_service.rb
dsu-2.4.3 lib/dsu/services/temp_file/writer_service.rb
dsu-2.4.2 lib/dsu/services/temp_file/writer_service.rb
dsu-2.4.1 lib/dsu/services/temp_file/writer_service.rb
dsu-2.4.0 lib/dsu/services/temp_file/writer_service.rb
dsu-2.3.2 lib/dsu/services/temp_file/writer_service.rb
dsu-2.3.1 lib/dsu/services/temp_file/writer_service.rb
dsu-2.3.0 lib/dsu/services/temp_file/writer_service.rb
dsu-2.2.2 lib/dsu/services/temp_file/writer_service.rb
dsu-2.2.1 lib/dsu/services/temp_file/writer_service.rb
dsu-2.2.0 lib/dsu/services/temp_file/writer_service.rb
dsu-2.2.0.rc.2 lib/dsu/services/temp_file/writer_service.rb
dsu-2.2.0.rc.1 lib/dsu/services/temp_file/writer_service.rb
dsu-2.1.4 lib/dsu/services/temp_file/writer_service.rb
dsu-2.1.3 lib/dsu/services/temp_file/writer_service.rb
dsu-2.1.2 lib/dsu/services/temp_file/writer_service.rb
dsu-2.1.1 lib/dsu/services/temp_file/writer_service.rb
dsu-2.0.8 lib/dsu/services/temp_file/writer_service.rb