Sha256: dea62915badedd2a85ce8ea8276e42fb914dbd26bae3e404b98e2d95ced60f61

Contents?: true

Size: 973 Bytes

Versions: 1

Compression:

Stored size: 973 Bytes

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 Admin < ApplicationRecord
  validates :canvas_id, uniqueness: true, presence: true
  belongs_to :user, primary_key: :canvas_id, foreign_key: :canvas_user_id, optional: true
  belongs_to :role, primary_key: :canvas_id, foreign_key: :canvas_role_id, optional: true

  def self.create_or_update(admin_params)
    admin = Admin.find_or_initialize_by(canvas_id: admin_params['id'])

    admin.assign_attributes(role_name: admin_params['role'],
                            canvas_role_id: admin_params['role_id'],
                            user_data: admin_params['user'],
                            canvas_user_id: admin_params['user']['id'],
                            workflow_state: admin_params['workflow_state'])

    admin.save! if admin.changed?
    admin
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
canvas_sync-0.10.0 spec/dummy/app/models/admin.rb