Class: Course::Achievement

Inherits:
ApplicationRecord show all
Defined in:
app/models/course/achievement.rb

Defined Under Namespace

Modules: AchievementsHelper, ControllerHelper Classes: AchievementsController, Controller, CourseUsersController

Instance Method Summary collapse

Instance Method Details

#initialize_duplicate(duplicator, other) ⇒ Object


56
57
58
59
60
61
62
63
64
# File 'app/models/course/achievement.rb', line 56

def initialize_duplicate(duplicator, other)
  badge.duplicate_from(other.badge) if other.badge_url
  self.course = duplicator.options[:destination_course]
  self.published = false if duplicator.options[:unpublish_all]
  duplicate_conditions(duplicator, other)
  achievement_conditions << other.achievement_conditions.
                            select { |condition| duplicator.duplicated?(condition.conditional) }.
                            map { |condition| duplicator.duplicate(condition) }
end

#manually_awarded?Boolean

Returns if achievement is manually or automatically awarded.

Returns:

  • (Boolean)

    Whether the achievement is manually awarded.


34
35
36
37
38
# File 'app/models/course/achievement.rb', line 34

def manually_awarded?
  # TODO: Correct call should be conditions.empty?, but that results in an
  # exception due to polymorphism. To investigate.
  specific_conditions.empty?
end

#permitted_for!(course_user) ⇒ Object


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

def permitted_for!(course_user)
  return if conditions.empty?
  course_users << course_user unless course_users.exists?(course_user.id)
end

#precluded_for!(course_user) ⇒ Object


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

def precluded_for!(course_user)
  course_users.delete(course_user) if course_users.exists?(course_user.id)
end

#satisfiable?Boolean

Returns:

  • (Boolean)

52
53
54
# File 'app/models/course/achievement.rb', line 52

def satisfiable?
  published?
end

#set_defaultsObject

Set default values


27
28
29
# File 'app/models/course/achievement.rb', line 27

def set_defaults
  self.weight ||= 10
end

#to_partial_pathObject


22
23
24
# File 'app/models/course/achievement.rb', line 22

def to_partial_path
  'course/achievement/achievements/achievement'
end