Class: Dsu::Services::TempFile::WriterService
- Inherits:
-
Object
- Object
- Dsu::Services::TempFile::WriterService
- Defined in:
- lib/dsu/services/temp_file/writer_service.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tmp_file_content:, options: {}) ⇒ WriterService
constructor
A new instance of WriterService.
Constructor Details
#initialize(tmp_file_content:, options: {}) ⇒ WriterService
Returns a new instance of WriterService.
9 10 11 12 13 14 15 16 17 |
# File 'lib/dsu/services/temp_file/writer_service.rb', line 9 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 .nil? raise ArgumentError, 'options is the wrong object type' unless .is_a?(Hash) @tmp_file_content = tmp_file_content = || {} end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/dsu/services/temp_file/writer_service.rb', line 19 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 |