Class: Course

Inherits:
ApplicationRecord show all
Includes:
Mumuki::Domain::Helpers::Course, Mumuki::Domain::Syncable
Defined in:
app/models/course.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mumuki::Domain::Helpers::Course

#platform_class_name, #to_param

Methods included from Mumuki::Domain::Syncable

#platform_class_name, #sync_key

Methods inherited from ApplicationRecord

aggregate_of, all_except, defaults, #delete, #destroy!, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, #update_and_notify!, update_or_create!, whitelist_attributes

Class Method Details

.sync_key_id_fieldObject



48
49
50
# File 'app/models/course.rb', line 48

def self.sync_key_id_field
  :slug
end

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/course.rb', line 39

def closed?
  current_invitation.blank? || current_invitation.expired?
end

#current_invitationObject



15
16
17
# File 'app/models/course.rb', line 15

def current_invitation
  invitations.where('expiration_date > ?', Time.now).take
end

#generate_invitation!(expiration_date) ⇒ Object



43
44
45
46
# File 'app/models/course.rb', line 43

def generate_invitation!(expiration_date)
  invitation = invitations.build expiration_date: expiration_date, course: self
  invitation.save_and_notify!
end

#import_from_resource_h!(resource_h) ⇒ Object



19
20
21
# File 'app/models/course.rb', line 19

def import_from_resource_h!(resource_h)
  update! self.class.slice_resource_h(resource_h)
end

#invite!(expiration_date) ⇒ Object



31
32
33
34
35
36
37
# File 'app/models/course.rb', line 31

def invite!(expiration_date)
  if closed?
    generate_invitation! expiration_date
  else
    current_invitation
  end
end

#slug=(slug) ⇒ Object



23
24
25
26
27
28
29
# File 'app/models/course.rb', line 23

def slug=(slug)
  s = Mumukit::Auth::Slug.parse(slug)

  self[:slug] = slug
  self[:code] = s.course
  self[:organization_id] = Organization.locate!(s.organization).id
end