Class: TeacherSource

Inherits:
Object
  • Object
show all
Includes:
Celluloid, ETLProducer
Defined in:
lib/actors/teacher_source.rb

Overview

Source of teacher records from the database.

It loads teacher usernames for a specified semester that are assigned to at least one event in that semester. Loaded teachers are sent down the pipeline afterwards.

Instance Method Summary collapse

Methods included from ETLProducer

#buffer_empty?, #buffer_full?, #buffer_pop, #buffer_put, #emit_eof, #emit_row, #output=, #output_hungry?, #output_row, #process_eof, #produce_row, #receive_hungry

Methods included from ETLBase

#empty?, #eof_received?, #logger, #mark_empty!, #receive_eof, #unmark_empty!

Constructor Details

#initialize(output, semester) ⇒ TeacherSource

Returns a new instance of TeacherSource.


14
15
16
17
# File 'lib/actors/teacher_source.rb', line 14

def initialize(output, semester)
  self.output = output
  @semester = semester
end

Instance Method Details

#generate_rowString

Returns teacher username loaded from database.

Returns:

  • (String)

    teacher username loaded from database


20
21
22
# File 'lib/actors/teacher_source.rb', line 20

def generate_row
  @teachers.next
end

#load_teachersObject


24
25
26
27
28
29
30
# File 'lib/actors/teacher_source.rb', line 24

def load_teachers
  teachers_dataset = Event
    .select { UNNEST(teacher_ids) }
    .distinct
    .where(faculty: @semester.faculty, semester: @semester.code)
  teachers_dataset.lazy.map { |e| e[:unnest] }
end

#start!Object


32
33
34
35
# File 'lib/actors/teacher_source.rb', line 32

def start!
  @teachers = load_teachers
  produce_row()
end