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.5 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.4 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.3 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.1 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.beta.3 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.beta.2 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.beta.1 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.beta.0 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.12 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.11 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.10 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.9 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.8 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.7 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.6 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.5 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.4 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.3 lib/dsu/services/temp_file/writer_service.rb
dsu-3.0.0.alpha.2 lib/dsu/services/temp_file/writer_service.rb