Sha256: ff340f8ce0e0927ea5f81495d663ef153176215b0545e9cf7f20e5eae6040465

Contents?: true

Size: 997 Bytes

Versions: 2

Compression:

Stored size: 997 Bytes

Contents

# frozen_string_literal: true

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

        @temp_file_path = temp_file_path
        @options = options || {}
      end

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

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

      private

      attr_reader :temp_file_path, :options
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dsu-0.1.0.alpha.4 lib/dsu/services/temp_file_reader_service.rb
dsu-0.1.0.alpha.3 lib/dsu/services/temp_file_reader_service.rb