Class: Course

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Syncable

#platform_class_name, #sync_key

Methods inherited from ApplicationRecord

aggregate_of, all_except, defaults, numbered, #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



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

def self.sync_key_id_field
  :slug
end

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)


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

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

#current_invitationObject



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

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

#generate_invitation!(expiration_date) ⇒ Object



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

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



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

def import_from_resource_h!(resource_h)
  update! Mumukit::Platform::Course::Helpers.slice_platform_json(resource_h)
end

#invite!(expiration_date) ⇒ Object



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

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

#slug=(slug) ⇒ Object



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

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