Sha256: ca2aa11219e04c382f4dfa71f1b13c5b74ba4ecf24a6de317b51710684b0af77

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

<%= autogenerated_model_warning %>

class Term < ApplicationRecord
  validates :canvas_id, uniqueness: true, presence: true
  has_many :courses, foreign_key: :canvas_term_id, primary_key: :canvas_id

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

  def self.create_or_update(term_params)
    term = Term.find_or_initialize_by(canvas_id: term_params['id'])

    term.assign_attributes(name: term_params['name'],
                           start_at: term_params['start_at'],
                           end_at: term_params['end_at'],
                           workflow_state: term_params['workflow_state'],
                           grading_period_group_id: term_params['grading_period_group_id'],
                           sis_id: term_params['sis_term_id'])

    term.save! if term.changed?
    term
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
canvas_sync-0.10.0 lib/canvas_sync/generators/templates/models/term.rb