Skip to content

Commit 267f268

Browse files
committed
Code style for lib
1 parent 09df6c6 commit 267f268

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+172
-68
lines changed

lib/background_course_refresher.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class BackgroundCourseRefresher
24
# Called periodically by script/background_daemon, does full refresh on courses which
35
# still need full initial refresh.

lib/background_task_registry.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module BackgroundTaskRegistry
24
def self.register(cls)
35
classes << cls

lib/course_info.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'natsort'
24

35
# Builds /courses/:id.json
@@ -45,7 +47,7 @@ def course_data_core_api(course)
4547
exercises.where(unlock_spec: nil)
4648
else
4749
exercises.where(["unlock_spec IS NULL OR exercises.name IN (#{@unlocked_exercises.map { |_| '?' }.join(', ')})", *@unlocked_exercises])
48-
end.select { |e| e._fast_visible? }
50+
end.select(&:_fast_visible?)
4951
end
5052

5153
exercises = exercises.to_a.natsort_by(&:name)

lib/course_list.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Builds /courses.json
24
class CourseList
35
def initialize(user, helpers)

lib/course_refresher.rb

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'find'
24
require 'pathname'
35
require 'recursive_yaml_reader'
@@ -97,44 +99,42 @@ def refresh_course(course, options)
9799
# I prefer suggestion 1.
98100

99101
Course.transaction(requires_new: true) do
100-
begin
101-
@course = Course.lock(true).find(course.id)
102-
103-
@old_cache_path = @course.cache_path
104-
105-
@course.increment_cache_version unless options[:no_directory_changes] # causes @course.*_path to return paths in the new cache
106-
107-
FileUtils.rm_rf(@course.cache_path) unless options[:no_directory_changes]
108-
FileUtils.mkdir_p(@course.cache_path) unless options[:no_directory_changes]
109-
110-
measure_and_log :update_or_clone_repository unless options[:no_directory_changes]
111-
measure_and_log :check_directory_names unless options[:no_directory_changes]
112-
measure_and_log :update_course_options
113-
measure_and_log :add_records_for_new_exercises
114-
measure_and_log :delete_records_for_removed_exercises
115-
measure_and_log :update_exercise_options
116-
measure_and_log :set_has_tests_flags
117-
measure_and_log :update_available_points, options[:no_directory_changes] unless options[:no_background_operations]
118-
measure_and_log :make_solutions unless options[:no_directory_changes]
119-
measure_and_log :make_stubs unless options[:no_directory_changes]
120-
measure_and_log :checksum_stubs
121-
measure_and_log :make_zips_of_stubs unless options[:no_directory_changes]
122-
measure_and_log :make_zips_of_solutions unless options[:no_directory_changes]
123-
measure_and_log :set_permissions unless options[:no_directory_changes]
124-
measure_and_log :invalidate_unlocks
125-
126-
@course.course_template.save!
127-
@course.refreshed_at = Time.now
128-
@course.save!
129-
@course.exercises.each &:save!
130-
131-
CourseRefresher.simulate_failure! if ::Rails.env.test? && CourseRefresher.respond_to?('simulate_failure!')
132-
rescue StandardError, ScriptError # Some YAML parsers throw ScriptError on syntax errors
133-
@report.errors << $!.message + "\n" + $!.backtrace.join("\n")
134-
# Delete the new cache we were working on
135-
FileUtils.rm_rf(@course.cache_path) unless options[:no_directory_changes]
136-
raise ActiveRecord::Rollback
137-
end
102+
@course = Course.lock(true).find(course.id)
103+
104+
@old_cache_path = @course.cache_path
105+
106+
@course.increment_cache_version unless options[:no_directory_changes] # causes @course.*_path to return paths in the new cache
107+
108+
FileUtils.rm_rf(@course.cache_path) unless options[:no_directory_changes]
109+
FileUtils.mkdir_p(@course.cache_path) unless options[:no_directory_changes]
110+
111+
measure_and_log :update_or_clone_repository unless options[:no_directory_changes]
112+
measure_and_log :check_directory_names unless options[:no_directory_changes]
113+
measure_and_log :update_course_options
114+
measure_and_log :add_records_for_new_exercises
115+
measure_and_log :delete_records_for_removed_exercises
116+
measure_and_log :update_exercise_options
117+
measure_and_log :set_has_tests_flags
118+
measure_and_log :update_available_points, options[:no_directory_changes] unless options[:no_background_operations]
119+
measure_and_log :make_solutions unless options[:no_directory_changes]
120+
measure_and_log :make_stubs unless options[:no_directory_changes]
121+
measure_and_log :checksum_stubs
122+
measure_and_log :make_zips_of_stubs unless options[:no_directory_changes]
123+
measure_and_log :make_zips_of_solutions unless options[:no_directory_changes]
124+
measure_and_log :set_permissions unless options[:no_directory_changes]
125+
measure_and_log :invalidate_unlocks
126+
127+
@course.course_template.save!
128+
@course.refreshed_at = Time.now
129+
@course.save!
130+
@course.exercises.each &:save!
131+
132+
CourseRefresher.simulate_failure! if ::Rails.env.test? && CourseRefresher.respond_to?('simulate_failure!')
133+
rescue StandardError, ScriptError # Some YAML parsers throw ScriptError on syntax errors
134+
@report.errors << $!.message + "\n" + $!.backtrace.join("\n")
135+
# Delete the new cache we were working on
136+
FileUtils.rm_rf(@course.cache_path) unless options[:no_directory_changes]
137+
raise ActiveRecord::Rollback
138138
end
139139

140140
if @report.errors.empty? && !options[:no_directory_changes]
@@ -236,24 +236,22 @@ def update_exercise_options
236236
reader = RecursiveYamlReader.new
237237
@review_points = {}
238238
@course.exercises.each do |e|
239-
begin
240-
metadata = reader.read_settings(root_dir: @course.clone_path,
241-
target_dir: File.join(@course.clone_path, e.relative_path),
242-
file_name: 'metadata.yml',
243-
defaults: Exercise.default_options,
244-
file_preprocessor: proc do |opts|
245-
merge_course_specific_suboptions(opts)
246-
end)
247-
@review_points[e.name] = parse_review_points(metadata['review_points'])
248-
249-
e.options = metadata
250-
251-
e.disabled! if e.new_record? && e.course.refreshed?
252-
253-
e.save!
254-
rescue SyntaxError
255-
@report.errors << "Failed to parse metadata: #{$!}"
256-
end
239+
metadata = reader.read_settings(root_dir: @course.clone_path,
240+
target_dir: File.join(@course.clone_path, e.relative_path),
241+
file_name: 'metadata.yml',
242+
defaults: Exercise.default_options,
243+
file_preprocessor: proc do |opts|
244+
merge_course_specific_suboptions(opts)
245+
end)
246+
@review_points[e.name] = parse_review_points(metadata['review_points'])
247+
248+
e.options = metadata
249+
250+
e.disabled! if e.new_record? && e.course.refreshed?
251+
252+
e.save!
253+
rescue SyntaxError
254+
@report.errors << "Failed to parse metadata: #{$!}"
257255
end
258256
end
259257

lib/course_refresher/block_comment_based_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'pathname'
24

35
class CourseRefresher

lib/course_refresher/css_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'pathname'
24
require 'course_refresher/block_comment_based_filter'
35

lib/course_refresher/exercise_file_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'pathname'
24
require 'fileutils'
35
require 'mimemagic'

lib/course_refresher/java_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'pathname'
24
require 'course_refresher/line_comment_based_filter'
35

lib/course_refresher/js_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'pathname'
24
require 'course_refresher/line_comment_based_filter'
35

0 commit comments

Comments
 (0)