Class: Gaku::StudentSelection

Inherits:
Object
  • Object
show all
Defined in:
app/services/gaku/student_selection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ StudentSelection

Returns a new instance of StudentSelection.



6
7
8
# File 'app/services/gaku/student_selection.rb', line 6

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject

Returns the value of attribute user.



4
5
6
# File 'app/services/gaku/student_selection.rb', line 4

def user
  @user
end

Instance Method Details

#add(student) ⇒ Object



19
20
21
22
# File 'app/services/gaku/student_selection.rb', line 19

def add(student)
  $redis.rpush(user_selection, student.id)
  self.students
end

#allObject



10
11
12
# File 'app/services/gaku/student_selection.rb', line 10

def all
  $redis.lrange(user_selection, 0, -1)
end

#collection(students) ⇒ Object



29
30
31
32
33
# File 'app/services/gaku/student_selection.rb', line 29

def collection(students)
  new_students = not_added_students(students)
  $redis.rpush(user_selection, new_students) unless new_students.blank?
  self.students
end

#remove(student) ⇒ Object



24
25
26
27
# File 'app/services/gaku/student_selection.rb', line 24

def remove(student)
  $redis.lrem(user_selection, 0, student.id)
  self.students
end

#remove_allObject



14
15
16
17
# File 'app/services/gaku/student_selection.rb', line 14

def remove_all
  $redis.del(user_selection)
  self.students
end

#remove_collection(students) ⇒ Object



35
36
37
38
39
40
# File 'app/services/gaku/student_selection.rb', line 35

def remove_collection(students)
  students.each do |student|
    $redis.lrem(user_selection, 0, student.id)
  end
  self.students
end

#studentsObject



42
43
44
# File 'app/services/gaku/student_selection.rb', line 42

def students
  Student.where(id: all)
end