Sha256: 1da35415ec50c31d4a5b976a1c16b65d840e2cd9378e73a88c721aae4eca1cd5

Contents?: true

Size: 1.54 KB

Versions: 117

Compression:

Stored size: 1.54 KB

Contents

# #
# AUTO GENERATED LIVE EVENT
# This was auto generated by the CanvasSync Gem.
# You can customize it as needed, but make sure you test
# any changes you make to the auto generated methods.
#
# LiveEvent message formats can be found at https://canvas.instructure.com/doc/api/file.live_events.html
# In the general case, LiveEvent message content should not be trusted - it is highly possible that events may
# arrive out of order. Most of the CanvasSync LiveEvent templates solve this by always fetching the object from the API.
#


module LiveEvents
  class AssignmentEvent < LiveEvents::BaseEvent

    def process
      canvas_assignment_id = local_canvas_id(payload[:assignment_id])
      assignment = Assignment.where(canvas_id: canvas_assignment_id).first_or_initialize
      assignment.context_id = canvas_course_id
      assignment.sync_from_api
    end

    private

    # This could be nil if the context type for this assignment is not 'Course' of if a local course was not found
    def canvas_course_id
      payload[:context_type] == "Course" ? local_canvas_id(payload[:context_id]) : nil
    end

    # This could be nil if the context type for this assignment is not 'Course' of if a local course was not found
    def course
      @course ||= begin
        course = Course.where(canvas_id: canvas_course_id).first_or_initialize
        course.sync_from_api unless course.persisted?
        course
      end
    end

  end

  class AssignmentCreatedEvent < LiveEvents::AssignmentEvent; end
  class AssignmentUpdatedEvent < LiveEvents::AssignmentEvent; end
end

Version data entries

117 entries across 117 versions & 1 rubygems

Version Path
canvas_sync-0.17.31 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.30 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.29 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.28 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.27 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.27.beta1 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.26.beta1 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.24 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.23 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.23.beta8 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.23.beta7 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.23.beta6 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.23.beta5 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.23.beta4 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.23.beta2 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.23.beta1 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.20 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.19 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.18 spec/dummy/app/services/live_events/assignment_event.rb
canvas_sync-0.17.17.beta1 spec/dummy/app/services/live_events/assignment_event.rb