Class: Mumuki::Domain::Submission::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/mumuki/domain/submission/base.rb

Direct Known Subclasses

ConsoleSubmission, PersistentSubmission, Question

Constant Summary collapse

ATTRIBUTES =
[:solution, :status, :result, :expectation_results, :feedback, :test_results,
:submission_id, :queries, :query_results, :manual_evaluation_comment]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client_resultObject

Returns the value of attribute client_result.



12
13
14
# File 'lib/mumuki/domain/submission/base.rb', line 12

def client_result
  @client_result
end

Class Method Details

.from_attributes(*args) ⇒ Object



14
15
16
# File 'lib/mumuki/domain/submission/base.rb', line 14

def self.from_attributes(*args)
  new ATTRIBUTES.zip(args).to_h
end

.mapping_attributesObject



18
19
20
# File 'lib/mumuki/domain/submission/base.rb', line 18

def self.mapping_attributes
  ATTRIBUTES
end

Instance Method Details

#dry_run!(assignment, _evaluation) ⇒ Object

By default evaluation strategy is ignored. Subclasses may override this behaviour



32
33
34
# File 'lib/mumuki/domain/submission/base.rb', line 32

def dry_run!(assignment, _evaluation)
  evaluate! assignment
end

#evaluate!(assignment) ⇒ Object



41
42
43
44
45
46
# File 'lib/mumuki/domain/submission/base.rb', line 41

def evaluate!(assignment)
  try_evaluate! assignment
rescue => e
  Rails.logger.error "Evaluation failed: #{e} \n#{e.backtrace.join("\n")}"
  {status: :errored, result: e.message}
end

#idObject



48
49
50
# File 'lib/mumuki/domain/submission/base.rb', line 48

def id
  @id ||= SecureRandom.hex(8)
end

#run!(assignment, evaluation) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/mumuki/domain/submission/base.rb', line 22

def run!(assignment, evaluation)
  save_submission! assignment
  results = dry_run! assignment, evaluation
  save_results! results, assignment
  notify_results! results, assignment
  results
end

#with_client_result(result) ⇒ Object



36
37
38
39
# File 'lib/mumuki/domain/submission/base.rb', line 36

def with_client_result(result)
  self.client_result = result if result.present?
  self
end