@@ -128,11 +128,11 @@ def refresh_course(course, options)
128
128
@course . save!
129
129
@course . exercises . each &:save!
130
130
131
- CourseRefresher . simulate_failure! if ::Rails . env == ' test' && CourseRefresher . respond_to? ( 'simulate_failure!' )
131
+ CourseRefresher . simulate_failure! if ::Rails . env . test? && CourseRefresher . respond_to? ( 'simulate_failure!' )
132
132
rescue StandardError , ScriptError # Some YAML parsers throw ScriptError on syntax errors
133
133
@report . errors << $!. message + "\n " + $!. backtrace . join ( "\n " )
134
134
# Delete the new cache we were working on
135
- FileUtils . rm_rf ( @course . cache_path ) unless options [ :no_directory_changes ]
135
+ FileUtils . rm_rf ( @course . cache_path ) unless options [ :no_directory_changes ]
136
136
raise ActiveRecord ::Rollback
137
137
end
138
138
end
@@ -143,18 +143,18 @@ def refresh_course(course, options)
143
143
end
144
144
145
145
course . reload # reload the record given as parameter
146
- fail Failure . new ( @report ) unless @report . errors . empty?
146
+ raise Failure , @report unless @report . errors . empty?
147
147
@report
148
148
end
149
149
150
150
def update_or_clone_repository
151
- fail 'Source types other than git not yet implemented' if @course . source_backend != 'git'
151
+ raise 'Source types other than git not yet implemented' if @course . source_backend != 'git'
152
152
153
153
if File . exist? ( "#{ @old_cache_path } /clone/.git" )
154
154
begin
155
155
# Try a fast path: copy old clone and git fetch new stuff
156
156
copy_and_update_repository
157
- rescue
157
+ rescue StandardError
158
158
FileUtils . rm_rf ( @course . clone_path )
159
159
clone_repository
160
160
end
@@ -164,7 +164,7 @@ def update_or_clone_repository
164
164
end
165
165
166
166
def copy_and_update_repository
167
- FileUtils . cp_r ( "#{ @old_cache_path } /clone" , " #{ @course . clone_path } " )
167
+ FileUtils . cp_r ( "#{ @old_cache_path } /clone" , @course . clone_path . to_s )
168
168
Dir . chdir ( @course . clone_path ) do
169
169
sh! ( 'git' , 'remote' , 'set-url' , 'origin' , @course . source_url )
170
170
sh! ( 'git' , 'fetch' , 'origin' )
@@ -184,7 +184,7 @@ def check_directory_names
184
184
Find . find ( @course . clone_path ) do |path |
185
185
relpath = path [ @course . clone_path . length ..-1 ]
186
186
if File . directory? ( path ) && exdirs . any? { |exdir | exdir . start_with? ( path ) } && relpath . include? ( '-' )
187
- fail "The directory #{ path } contains a dash (-). Currently that is forbidden. Sorry."
187
+ raise "The directory #{ path } contains a dash (-). Currently that is forbidden. Sorry."
188
188
end
189
189
end
190
190
end
@@ -248,9 +248,7 @@ def update_exercise_options
248
248
249
249
e . options = metadata
250
250
251
- if ( e . new_record? && e . course . refreshed? )
252
- e . disabled!
253
- end
251
+ e . disabled! if e . new_record? && e . course . refreshed?
254
252
255
253
e . save!
256
254
rescue SyntaxError
@@ -290,23 +288,22 @@ def update_available_points(no_directory_changes = false)
290
288
clone_path = Pathname ( "#{ @course . clone_path } /#{ exercise . relative_path } " )
291
289
292
290
points_data = points_for ( exercise , no_directory_changes )
293
- if points_data [ 0 ] . is_a? Hash
294
- point_names += points_data . map { |x | x [ :points ] } . flatten
295
- else
296
- point_names += points_data . flatten
297
- end
291
+ point_names += if points_data [ 0 ] . is_a? Hash
292
+ points_data . map { |x | x [ :points ] } . flatten
293
+ else
294
+ points_data . flatten
295
+ end
298
296
299
297
point_names += review_points
300
298
301
299
added = [ ]
302
300
removed = [ ]
303
301
304
302
point_names . each do |name |
305
- if exercise . available_points . none? { |point | point . name == name }
306
- added << name
307
- point = AvailablePoint . create ( name : name , exercise : exercise )
308
- exercise . available_points << point
309
- end
303
+ next unless exercise . available_points . none? { |point | point . name == name }
304
+ added << name
305
+ point = AvailablePoint . create ( name : name , exercise : exercise )
306
+ exercise . available_points << point
310
307
end
311
308
312
309
exercise . available_points . to_a . clone . each do |point |
@@ -334,19 +331,19 @@ def get_c_exercise_points(exercise)
334
331
TestScannerCache . get_or_update ( @course , exercise . name , hash ) do
335
332
all_points = Set . new
336
333
Dir . chdir ( full_path ) do
337
- sh! ( %w( make test ) )
338
- sh! ( %w( make get-points > points.txt ) , { escape : false } )
334
+ sh! ( %w[ make test ] )
335
+ sh! ( %w[ make get-points > points.txt ] , escape : false )
339
336
340
337
tmc_available_points = File . join ( full_path , 'test' , 'tmc_available_points.txt' )
341
- if File . exists ? tmc_available_points
338
+ if File . exist ? tmc_available_points
342
339
IO . readlines ( tmc_available_points ) . map ( &:strip ) . each do |line |
343
340
if line =~ /\[ .*\] \[ .*\] (.*)/
344
- $1 . split ( ' ' ) . map ( &:strip ) . each { |p | all_points << p }
341
+ Regexp . last_match ( 1 ) . split ( ' ' ) . map ( &:strip ) . each { |p | all_points << p }
345
342
else
346
343
raise "Warning: weird line in available points file: #{ line } "
347
344
end
348
345
end
349
- elsif File . exists ?( File . join ( full_path , 'points.txt' ) )
346
+ elsif File . exist ?( File . join ( full_path , 'points.txt' ) )
350
347
available_points_content = IO . readlines ( "#{ full_path } /points.txt" )
351
348
# drop makefile output
352
349
# This is how initial check tests used to work.
@@ -360,8 +357,8 @@ def get_c_exercise_points(exercise)
360
357
raise "Could not extract points for makefile exercise: #{ exercise } "
361
358
end
362
359
363
- sh! ( %w( make clean ) )
364
- FileUtils . rm ( "#{ full_path } /points.txt" ) if File . exists ?( File . join ( full_path , 'points.txt' ) )
360
+ sh! ( %w[ make clean ] )
361
+ FileUtils . rm ( "#{ full_path } /points.txt" ) if File . exist ?( File . join ( full_path , 'points.txt' ) )
365
362
end
366
363
all_points
367
364
end
@@ -461,12 +458,12 @@ def set_permissions
461
458
parent_dirs = Course . cache_root . sub ( ::Rails . root . to_s , '' ) . split ( '/' ) . reject ( &:blank? )
462
459
( 0 ..( parent_dirs . length ) ) . each do |i |
463
460
dir = "#{ ::Rails . root } /#{ parent_dirs [ 0 ..i ] . join ( '/' ) } "
464
- sh! ( 'chmod' , chmod , dir ) unless chmod . blank ?
465
- sh! ( 'chgrp' , chgrp , dir ) unless chgrp . blank ?
461
+ sh! ( 'chmod' , chmod , dir ) if chmod . present ?
462
+ sh! ( 'chgrp' , chgrp , dir ) if chgrp . present ?
466
463
end
467
464
468
- sh! ( 'chmod' , '-R' , chmod , @course . cache_path ) unless chmod . blank ?
469
- sh! ( 'chgrp' , '-R' , chgrp , @course . cache_path ) unless chgrp . blank ?
465
+ sh! ( 'chmod' , '-R' , chmod , @course . cache_path ) if chmod . present ?
466
+ sh! ( 'chgrp' , '-R' , chgrp , @course . cache_path ) if chgrp . present ?
470
467
end
471
468
472
469
def invalidate_unlocks
0 commit comments