Class: Course::Assessment::Question::Programming::ProgrammingPackageService

Inherits:
Object
  • Object
show all
Defined in:
app/services/course/assessment/question/programming/programming_package_service.rb

Overview

Generates the package and extracts the meta for the programming question based on the language of the programming question.

Instance Method Summary collapse

Constructor Details

#initialize(question, params) ⇒ ProgrammingPackageService

Creates a new programming package service object.

Parameters:


9
10
11
12
13
14
15
# File 'app/services/course/assessment/question/programming/programming_package_service.rb', line 9

def initialize(question, params)
  @question = question
  @language = question.language
  @template_files = question.template_files

  init_language_package_service(params)
end

Instance Method Details

#extract_metaHash

Retrieves the meta details from the programming package.

Returns:

  • (Hash)

35
36
37
38
# File 'app/services/course/assessment/question/programming/programming_package_service.rb', line 35

def extract_meta
  data = @language_package_service.extract_meta(@question.attachment, @template_files)
  { editor_mode: @language.ace_mode, data: data } if data.present?
end

#generate_packageObject

Generates a programming package from the parameters which were passed to the controller.


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/course/assessment/question/programming/programming_package_service.rb', line 18

def generate_package
  if @language_package_service.autograded?
    new_package = @language_package_service.generate_package(@question.attachment)
    @question.file = new_package if new_package.present?
  else
    templates = @language_package_service.submission_templates
    @question.imported_attachment = nil
    @question.import_job_id = nil
    @question.non_autograded_template_files = templates.map do |template|
      Course::Assessment::Question::ProgrammingTemplateFile.new(template)
    end
  end
end