Sha256: 90ab1cac2f4bf92f095c79f370afd37792e19106f8b9bec1b4efc05bfc07b4bf

Contents?: true

Size: 1.03 KB

Versions: 27

Compression:

Stored size: 1.03 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.
#


module LiveEvents
  class SyllabusEvent < LiveEvents::BaseEvent
    # The following is provided in the live events call:
    # {
    #   course_id: course.global_id,
    #   syllabus_body: LiveEvents.truncate(course.syllabus_body),
    #   old_syllabus_body: LiveEvents.truncate(old_syllabus_body)
    # }
    #

    def perform(event_payload)
      super
      attrs = {
        course_id: course.try(:id),
        syllabus_body: payload[:syllabus_body],
      }
      create_or_update(attrs)
    end

    private

    def create_or_update(attrs)
      syllabus = Syllabus.where(course_id: attrs[:course_id]).first_or_initialize
      syllabus.body = attrs[:syllabus_body] # Syllabus Body can get truncated by live events
      syllabus.save!
    end

    def course
      Course.find_by(canvas_course_id: local_canvas_id(payload[:course_id]))
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
canvas_sync-0.10.2 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.10.0 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.9.4 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.9.3 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.9.2 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.9.1 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.9.0 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.8.4 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.8.3 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.8.2 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.8.1 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.8.0 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.7.3 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.7.2 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.7.1 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.7.0 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.6.4 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.6.3 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.6.2 spec/dummy/app/services/live_events/syllabus_event.rb
canvas_sync-0.6.1 spec/dummy/app/services/live_events/syllabus_event.rb