Class: Invitation

Inherits:
ApplicationRecord show all
Includes:
Mumuki::Domain::Syncable, WithGeneratedCode
Defined in:
app/models/invitation.rb

Instance Method Summary collapse

Methods included from Mumuki::Domain::Syncable

#platform_class_name, #sync_key

Methods inherited from ApplicationRecord

active_between, aggregate_of, all_except, defaults, #delete, #destroy!, enum_prefixed_translations_for, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, teaser_on, #update_and_notify!, update_or_create!, whitelist_attributes, with_pg_retry, with_temporary_token

Methods included from WithPgLock

#with_pg_lock

Instance Method Details

#course_slugObject



21
22
23
# File 'app/models/invitation.rb', line 21

def course_slug
  course.slug
end

#ensure_not_expiredObject



9
10
11
# File 'app/models/invitation.rb', line 9

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

#expired?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/invitation.rb', line 41

def expired?
  expiration_date.past?
end

#import_from_resource_h!(json) ⇒ Object



13
14
15
# File 'app/models/invitation.rb', line 13

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


25
26
27
# File 'app/models/invitation.rb', line 25

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

Returns:

  • (Boolean)


33
34
35
# File 'app/models/invitation.rb', line 33

def navigation_end?
  true
end

#organizationObject



17
18
19
# File 'app/models/invitation.rb', line 17

def organization
  course.organization
end

#to_paramObject



37
38
39
# File 'app/models/invitation.rb', line 37

def to_param
  code
end

#to_resource_hObject



29
30
31
# File 'app/models/invitation.rb', line 29

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

#unexpiredObject



45
46
47
48
# File 'app/models/invitation.rb', line 45

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