Class: GradingChecker::FileManager

Inherits:
Object
  • Object
show all
Defined in:
lib/grading_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ FileManager

Returns a new instance of FileManager.



16
17
18
# File 'lib/grading_checker.rb', line 16

def initialize(root_path)
    @root_path = Pathname.new(root_path)
end

Instance Attribute Details

#root_pathObject (readonly)

Returns the value of attribute root_path.



14
15
16
# File 'lib/grading_checker.rb', line 14

def root_path
  @root_path
end

Instance Method Details

#find_grading_ymlsObject



28
29
30
# File 'lib/grading_checker.rb', line 28

def find_grading_ymls
    @root_path.find.select { |path| path.file? && path.basename.to_s == "grading.yml" }
end

#find_submit_ymlsObject



32
33
34
# File 'lib/grading_checker.rb', line 32

def find_submit_ymls
    @root_path.find.select { |path| path.file? && path.basename.to_s == "submit.yml" }
end

#load_yaml(file_path) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/grading_checker.rb', line 20

def load_yaml(file_path)
    return {} unless file_path.exist?

    YAML.load_file(file_path, aliases: true) || {}
rescue StandardError => e
    abort("Error loading YAML file: #{file_path}\n#{e.message}")
end

#merge_configs(grades1, grades2) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/grading_checker.rb', line 36

def merge_configs(grades1, grades2)
    first_without_grades = grades1.reject { |k, _| %w[templates grades calculation].include?(k) }
    second_without_grades = grades2.reject { |k, _| %w[templates grades calculation].include?(k) }

    merged_grades = (grades1["grades"] || {}).merge(grades2["grades"] || {})
    merged_calculation = (grades1["calculation"] || {}).merge(grades2["calculation"] || {})
    merged_rest = first_without_grades.merge(second_without_grades)
    merged_rest["grades"] = merged_grades
    merged_rest["calculation"] = merged_calculation

    merged_rest
end