Class: Mumuki::Classroom::Event::ProgressTransfer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mumuki/classroom/event/progress_transfer/base.rb

Direct Known Subclasses

Copy, Move

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(indicator, source_organization, destination_organization) ⇒ Base

Returns a new instance of Base.



4
5
6
7
8
# File 'lib/mumuki/classroom/event/progress_transfer/base.rb', line 4

def initialize(indicator, source_organization, destination_organization)
  @indicator = indicator
  @source_organization = source_organization
  @destination_organization = destination_organization
end

Instance Attribute Details

#indicatorObject (readonly)

Returns the value of attribute indicator.



2
3
4
# File 'lib/mumuki/classroom/event/progress_transfer/base.rb', line 2

def indicator
  @indicator
end

#source_organizationObject (readonly)

Returns the value of attribute source_organization.



2
3
4
# File 'lib/mumuki/classroom/event/progress_transfer/base.rb', line 2

def source_organization
  @source_organization
end

Instance Method Details

#execute!Object

Raises:

  • (ActiveRecord::RecordNotFound)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mumuki/classroom/event/progress_transfer/base.rb', line 10

def execute!
  raise ActiveRecord::RecordNotFound, "Mumuki::Classroom::Student not found" unless old_student && new_student

  new_student.destroy_progress_for_guide!(indicator.content)
  destination_organization.switch!

  indicator.assignments.each do |assignment|
    transfer_sibling_for(assignment)&.update! organization: destination_organization.name,
                                              course: new_course,
                                              guide: guide_h
  end

  transfer_guide_progress!
  update_student!(old_student)
  update_student!(new_student)
end