Class: Mumuki::Domain::ProgressTransfer::Base

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

Direct Known Subclasses

Copy, Move

Instance Method Summary collapse

Constructor Details

#initialize(progress_item, destination_organization) ⇒ Base

Returns a new instance of Base.



6
7
8
9
# File 'lib/mumuki/domain/progress_transfer/base.rb', line 6

def initialize(progress_item, destination_organization)
  @progress_item = progress_item
  @destination_organization = destination_organization
end

Instance Method Details

#execute!Object



11
12
13
14
15
16
17
# File 'lib/mumuki/domain/progress_transfer/base.rb', line 11

def execute!
  ActiveRecord::Base.transaction do
    pre_transfer!
    transfer!
    post_transfer!
  end
end

#notify_transfer!Object



41
42
43
# File 'lib/mumuki/domain/progress_transfer/base.rb', line 41

def notify_transfer!
  Mumukit::Nuntius.notify! 'progress-transfers', { from: source_organization.name, to: destination_organization.name, item_type: transferred_item.class.to_s, item_id: transferred_item.id, transfer_type: transfer_type }
end

#post_transfer!Object



29
30
31
32
33
# File 'lib/mumuki/domain/progress_transfer/base.rb', line 29

def post_transfer!
  transferred_item.dirty_parent_by_submission!
  notify_transfer!
  transferred_item
end

#pre_transfer!Object



19
20
21
22
23
# File 'lib/mumuki/domain/progress_transfer/base.rb', line 19

def pre_transfer!
  validate_transferrable!
  @source_organization = progress_item.organization
  progress_item.delete_duplicates_in!(destination_organization)
end

#transfer!Object



25
26
27
# File 'lib/mumuki/domain/progress_transfer/base.rb', line 25

def transfer!
  @transferred_item = do_transfer!
end

#validate_transferrable!Object



35
36
37
38
39
# File 'lib/mumuki/domain/progress_transfer/base.rb', line 35

def validate_transferrable!
  raise "Transferred progress' content must be available in destination!" unless progress_item.content_available_in?(destination_organization)
  raise 'User must be student in destination organization' unless user.student_of?(destination_organization)
  raise 'Transfer only supported for guide indicators' unless progress_item.guide_indicator?
end