Class: Course::Assessment::Category

Inherits:
ApplicationRecord show all
Includes:
ModelComponentHost::Component
Defined in:
app/models/course/assessment/category.rb

Overview

Represents a category of assessments. This is typically 'Mission' and 'Training'.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.after_course_initialize(course) ⇒ Object


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

def self.after_course_initialize(course)
  return if course.persisted? || !course.assessment_categories.empty?

  course.assessment_categories.
    build(title: human_attribute_name('title.default'), weight: 0)
end

Instance Method Details

#after_duplicate_save(duplicator) ⇒ Boolean

Returns true if post-duplication processing is successful.

Returns:

  • (Boolean)

    true if post-duplication processing is successful.


48
49
50
51
52
# File 'app/models/course/assessment/category.rb', line 48

def after_duplicate_save(duplicator)
  User.with_stamper(duplicator.options[:current_user]) do
    build_initial_tab ? save : true
  end
end

#initialize_duplicate(duplicator, other) ⇒ Object


37
38
39
40
41
42
43
44
45
# File 'app/models/course/assessment/category.rb', line 37

def initialize_duplicate(duplicator, other)
  self.folder = duplicator.duplicate(other.folder)
  self.course = duplicator.options[:destination_course]
  tabs << other.tabs.select { |tab| duplicator.duplicated?(tab) }.map do |tab|
    duplicator.duplicate(tab).tap do |duplicate_tab|
      duplicate_tab.assessments.each { |assessment| assessment.folder.parent = folder }
    end
  end
end

#other_categories_remaining?Boolean

Returns a boolean value indicating if there are other categories besides this one remaining in its course.

Returns:

  • (Boolean)

33
34
35
# File 'app/models/course/assessment/category.rb', line 33

def other_categories_remaining?
  course.assessment_categories.count > 1
end