Sha256: c179e72e01b45adf89efde12008fc095183951ca66ea739f3fb22e1b92634a49

Contents?: true

Size: 1.22 KB

Versions: 60

Compression:

Stored size: 1.22 KB

Contents

#
# AUTO GENERATED MODEL
# This model 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.
#


class Term < ApplicationRecord
  validates :canvas_term_id, uniqueness: true, presence: true
  has_many :courses, foreign_key: :canvas_term_id, primary_key: :canvas_term_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_term_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

60 entries across 60 versions & 1 rubygems

Version Path
canvas_sync-0.9.4 spec/dummy/app/models/term.rb
canvas_sync-0.9.3 spec/dummy/app/models/term.rb
canvas_sync-0.9.2 spec/dummy/app/models/term.rb
canvas_sync-0.9.1 spec/dummy/app/models/term.rb
canvas_sync-0.9.0 spec/dummy/app/models/term.rb
canvas_sync-0.8.4 spec/dummy/app/models/term.rb
canvas_sync-0.8.3 spec/dummy/app/models/term.rb
canvas_sync-0.8.2 spec/dummy/app/models/term.rb
canvas_sync-0.8.1 spec/dummy/app/models/term.rb
canvas_sync-0.8.0 spec/dummy/app/models/term.rb
canvas_sync-0.7.3 spec/dummy/app/models/term.rb
canvas_sync-0.7.2 spec/dummy/app/models/term.rb
canvas_sync-0.7.1 spec/dummy/app/models/term.rb
canvas_sync-0.7.0 spec/dummy/app/models/term.rb
canvas_sync-0.6.4 spec/dummy/app/models/term.rb
canvas_sync-0.6.3 spec/dummy/app/models/term.rb
canvas_sync-0.6.2 spec/dummy/app/models/term.rb
canvas_sync-0.6.1 spec/dummy/app/models/term.rb
canvas_sync-0.6.0 spec/dummy/app/models/term.rb
canvas_sync-0.5.4 spec/dummy/app/models/term.rb