Class: Course::Assessment::Question::Programming::LanguagePackageService

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

Overview

In charge of the programming package of the question when using the online editor. This will generate a package based on the parameters from the online editor for autograded questions, or extract the template files from the parameters for non-autograded questions.

This also extracts the meta details of the programming question, the meta is a JSON used by the online editor for rendering. This meta will be stored in the package for autograded questions, or generated using the existing template files and the default meta for non-autograded questions.

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ LanguagePackageService

A concrete language package service will be initalized with the request parameters from the controller when creating/updating the programming question, the language package service will use the parameters to create/update the package.

When using the service only to retrieve the meta for a programming question, the params argument can be nil.

Parameters:

  • params (ActionController::Parameters)

    The parameters containing the data for package generation.


19
20
21
# File 'app/services/course/assessment/question/programming/language_package_service.rb', line 19

def initialize(params)
  @test_params = test_params params if params.present?
end

Instance Method Details

#autograded?Boolean

Checks whether the programming question should be autograded.

Returns:

  • (Boolean)

26
27
28
# File 'app/services/course/assessment/question/programming/language_package_service.rb', line 26

def autograded?
  @test_params.key?(:autograded)
end

#default_metaHash

Defines the default meta to be used by the online editor for rendering.

Returns:

  • (Hash)

48
49
50
51
52
53
54
55
56
57
58
# File 'app/services/course/assessment/question/programming/language_package_service.rb', line 48

def default_meta
  {
    submission: '', solution: '', prepend: '', append: '',
    data_files: [],
    test_cases: {
      public: [],
      private: [],
      evaluation: []
    }
  }
end

#extract_meta(attachment, template_files) ⇒ Hash

Retrieves the meta details from the programming package, or the template files if the package does not exist for non-autograded questions.

Parameters:

Returns:

  • (Hash)

Raises:

  • (NotImplementedError)

67
68
69
# File 'app/services/course/assessment/question/programming/language_package_service.rb', line 67

def extract_meta(attachment, template_files) # rubocop:disable UnusedMethodArgument
  raise NotImplementedError, 'You must implement this'
end

#generate_package(old_attachment) ⇒ Tempfile

Generates a new package with the meta file.

Parameters:

Returns:

  • (Tempfile)

Raises:

  • (NotImplementedError)

41
42
43
# File 'app/services/course/assessment/question/programming/language_package_service.rb', line 41

def generate_package(old_attachment) # rubocop:disable UnusedMethodArgument
  raise NotImplementedError, 'You must implement this'
end

#submission_templatesArray

Array of arguments used to create template files for non-autograded programming question.

Returns:

  • (Array)

Raises:

  • (NotImplementedError)

33
34
35
# File 'app/services/course/assessment/question/programming/language_package_service.rb', line 33

def submission_templates
  raise NotImplementedError, 'You must implement this'
end