Sha256: 20ac7d0aa9a0db09478fe72da4cd4115eb7d742d00d09d188004f06af3e3fe0a

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

# <%= autogenerated_model_warning %>

class Term < ApplicationRecord
  include CanvasSync::ApiSyncable

  validates :canvas_id, uniqueness: true, presence: true
  has_many :courses, foreign_key: :canvas_term_id, primary_key: :canvas_id

  api_syncable({
    canvas_id: :id,
    name: :name,
    sis_id: :sis_term_id,
    start_at: :start_at,
    end_at: :end_at,
    workflow_state: :workflow_state,
    grading_period_group_id: :grading_period_group_id,
  }, -> (api) {
    terms = api.terms('self').all_pages!
    term_data = terms.find{|term| term['id'] == canvas_id }
    raise Footrest::HttpError::NotFound unless term_data.present?
    term_data
  })

  def self.create_or_update(params); find_or_initialize_by(canvas_id: params['id']).update_from_api_params!(params); end

  # This is a sample scope created by the CanvasSync gem; feel
  # free to customize it for your tool's requirements.
  scope :active, -> {
    where(workflow_state: 'active')
      .where("start_at <= ? OR start_at IS NULL", 15.days.from_now)
      .where("end_at >= ? OR end_at IS NULL", 15.days.ago)
  }

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
canvas_sync-0.10.6 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.10.5 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.10.4 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.10.3 lib/canvas_sync/generators/templates/models/term.rb