Sha256: 49ba8b6a9a5ead8128c8bb03a860c25a467dc2f6908a10f4b24bc0433359bc67

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

module Bright
  module SisApi
    class Base
      def filter_students_by_params(students, params)
        total = params[:limit]
        count = 0
        found = []

        keys = (Student.attribute_names & params.keys.collect(&:to_sym))
        puts "filtering on #{keys.join(",")}"
        students.each do |student|
          break if total and count >= total

          should = keys.all? do |m|
            student.send(m) =~ Regexp.new(Regexp.escape(params[m]), Regexp::IGNORECASE)
          end
          count += 1 if total and should
          found << student if should
        end
        found
      end

      def connection_retry_wrapper(&block)
        retry_attempts = connection_options[:retry_attempts] || 2
        retries = 0
        begin
          yield
        rescue Bright::ResponseError => e
          retries += 1
          if e.server_error? && retries <= retry_attempts.to_i
            puts "retrying #{retries}: #{e.class} - #{e}"
            sleep(retries * 3)
            retry
          else
            raise
          end
        rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Net::ReadTimeout, Net::OpenTimeout, SocketError, EOFError => e
          retries += 1
          if retries <= retry_attempts.to_i
            puts "retrying #{retries}: #{e.class} - #{e}"
            sleep(retries * 3)
            retry
          else
            raise
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bright-2.1 lib/bright/sis_apis/base.rb
bright-2.0 lib/bright/sis_apis/base.rb