Sha256: 66e1a2560aa8e961137a40b46d74d00c499d81a97f6b2d2022562cc5997285c2

Contents?: true

Size: 999 Bytes

Versions: 34

Compression:

Stored size: 999 Bytes

Contents

class Invitation < ApplicationRecord
  include Mumuki::Domain::Syncable,
          WithGeneratedCode

  belongs_to :course

  validate :ensure_not_expired, on: :create

  def ensure_not_expired
    errors.add(:base, :invitation_expired) if expired?
  end

  def import_from_resource_h!(json)
    update! json.merge(course: Course.locate!(json[:course]))
  end

  def organization
    course.organization
  end

  def course_slug
    course.slug
  end

  def navigable_name
    I18n.t(:invitation_for, course: course_name)
  end

  def to_resource_h
    {code: code, course: course_slug, expiration_date: expiration_date}
  end

  def navigation_end?
    true
  end

  def to_param
    code
  end

  def expired?
    expiration_date.past?
  end

  def unexpired
    raise Mumuki::Domain::GoneError, "This invitation has already expired" if expired?
    self
  end

  private

  def self.code_size
    4
  end

  def course_name
    course.name
  end

  def self.sync_key_id_field
    :code
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
mumuki-domain-9.23.0 app/models/invitation.rb
mumuki-domain-9.22.1 app/models/invitation.rb
mumuki-domain-9.22.0 app/models/invitation.rb
mumuki-domain-9.21.0 app/models/invitation.rb
mumuki-domain-9.20.0 app/models/invitation.rb
mumuki-domain-9.19.0 app/models/invitation.rb
mumuki-domain-9.18.0 app/models/invitation.rb
mumuki-domain-9.17.0 app/models/invitation.rb
mumuki-domain-9.16.0 app/models/invitation.rb
mumuki-domain-9.15.0 app/models/invitation.rb
mumuki-domain-9.14.1 app/models/invitation.rb
mumuki-domain-9.14.0 app/models/invitation.rb
mumuki-domain-9.13.1 app/models/invitation.rb
mumuki-domain-9.13.0 app/models/invitation.rb
mumuki-domain-9.12.0 app/models/invitation.rb
mumuki-domain-9.11.0 app/models/invitation.rb
mumuki-domain-9.10.0 app/models/invitation.rb
mumuki-domain-9.9.0 app/models/invitation.rb
mumuki-domain-9.8.1 app/models/invitation.rb
mumuki-domain-9.8.0 app/models/invitation.rb