reduced code complexity
This commit is contained in:
@ -13,10 +13,15 @@ class Submission < ActiveRecord::Base
|
|||||||
validates :cause, inclusion: {in: CAUSES}
|
validates :cause, inclusion: {in: CAUSES}
|
||||||
validates :exercise_id, presence: true
|
validates :exercise_id, presence: true
|
||||||
|
|
||||||
|
def build_files_hash(files, attribute)
|
||||||
|
files.map(&attribute.to_proc).zip(files).to_h
|
||||||
|
end
|
||||||
|
private :build_files_hash
|
||||||
|
|
||||||
def collect_files
|
def collect_files
|
||||||
ancestors = exercise.files.map(&:id).zip(exercise.files)
|
ancestors = build_files_hash(exercise.files, :id)
|
||||||
descendants = files.map(&:file_id).zip(files)
|
descendants = build_files_hash(files, :file_id)
|
||||||
(ancestors + descendants).to_h.values
|
ancestors.merge(descendants).values
|
||||||
end
|
end
|
||||||
|
|
||||||
def execution_environment
|
def execution_environment
|
||||||
|
Reference in New Issue
Block a user