Sha256: 7adcf7743312108658ef94775df93500d8c7fac964f7eb27c4303419c99d9dc0

Contents?: true

Size: 984 Bytes

Versions: 8

Compression:

Stored size: 984 Bytes

Contents

# frozen_string_literal: true

module Dsu
  module Services
    class TempFileReaderService
      def initialize(tmp_file_path:, options: {})
        raise ArgumentError, 'tmp_file_path is nil' if tmp_file_path.nil?
        raise ArgumentError, 'tmp_file_path is the wrong object type' unless tmp_file_path.is_a?(String)
        raise ArgumentError, 'tmp_file_path is empty' if tmp_file_path.empty?
        raise ArgumentError, 'tmp_file_path does not exist' unless File.exist?(tmp_file_path)
        raise ArgumentError, 'options is nil' if options.nil?
        raise ArgumentError, 'options is the wrong object type' unless options.is_a?(Hash)

        @tmp_file_path = tmp_file_path
        @options = options || {}
      end

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

        File.foreach(tmp_file_path) do |line|
          yield line.strip
        end
      end

      private

      attr_reader :tmp_file_path, :options
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dsu-1.2.1 lib/dsu/services/temp_file_reader_service.rb
dsu-1.2.0 lib/dsu/services/temp_file_reader_service.rb
dsu-1.1.2 lib/dsu/services/temp_file_reader_service.rb
dsu-1.1.1 lib/dsu/services/temp_file_reader_service.rb
dsu-1.1.0.alpha.2 lib/dsu/services/temp_file_reader_service.rb
dsu-1.1.0.alpha.1 lib/dsu/services/temp_file_reader_service.rb
dsu-1.0.0 lib/dsu/services/temp_file_reader_service.rb
dsu-0.1.0.alpha.5 lib/dsu/services/temp_file_reader_service.rb