Sha256: c6dec1ce5dc6e8efa43bcc74ec6ded3e9e66273a653691d3fac0acf131e1ac34

Contents?: true

Size: 1.13 KB

Versions: 53

Compression:

Stored size: 1.13 KB

Contents

# <%= autogenerated_model_warning %>

class Term < ApplicationRecord
  include CanvasSync::Record
  include CanvasSync::Concerns::ApiSyncable

  canvas_sync_features :defaults

  validates :canvas_id, uniqueness: true, presence: true
  has_many :courses, foreign_key: :canvas_term_id, primary_key: :canvas_id
  belongs_to :grading_period_group, primary_key: :canvas_id, foreign_key: :grading_period_group_id, optional: true

  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
  })

  # 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

53 entries across 53 versions & 1 rubygems

Version Path
canvas_sync-0.22.9 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.8 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.6 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.5 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.4 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.3 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.2 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.1 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.0 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.0.beta8 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.0.beta7 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.0.beta6 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.0.beta5 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.0.beta4 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.0.beta3 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.0.beta2 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.22.0.beta1 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.21.1 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.21.1.beta1 lib/canvas_sync/generators/templates/models/term.rb
canvas_sync-0.21.0 lib/canvas_sync/generators/templates/models/term.rb