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