class Daigaku::Solution
Constants
- FILE_SUFFIX
Attributes
code[R]
errors[R]
path[R]
Public Class Methods
new(unit_path)
click to toggle source
# File lib/daigaku/solution.rb, line 7 def initialize(unit_path) @unit_path = unit_path @path = solution_path(unit_path) @code = load_code(@path) @verified = store_state end
Public Instance Methods
store_key()
click to toggle source
# File lib/daigaku/solution.rb, line 25 def store_key unless @store_key part_path = path.split('/')[-3..-1].join('/').gsub(FILE_SUFFIX, '') @store_key = Storeable.key(part_path, prefix: 'verified') end @store_key end
verified?()
click to toggle source
# File lib/daigaku/solution.rb, line 21 def verified? !!@verified end
verify!()
click to toggle source
# File lib/daigaku/solution.rb, line 14 def verify! @code = load_code(@path) result = Daigaku::Test.new(@unit_path).run(@code) self.store_state = result.passed? result end
Private Instance Methods
directory_from(path)
click to toggle source
# File lib/daigaku/solution.rb, line 48 def directory_from(path) path.split('/')[-3..-2].join('/').gsub(FILE_SUFFIX, '') end
load_code(path)
click to toggle source
# File lib/daigaku/solution.rb, line 36 def load_code(path) File.read(path).strip if File.file?(path) end
solution_path(path)
click to toggle source
# File lib/daigaku/solution.rb, line 40 def solution_path(path) local_path = Daigaku.config.solutions_path sub_directory = Storeable.key(directory_from(path)) file = Storeable.key(File.basename(path)) + FILE_SUFFIX File.join(local_path, sub_directory, file) end
store_state()
click to toggle source
# File lib/daigaku/solution.rb, line 57 def store_state QuickStore.store.get(store_key) end
store_state=(verified)
click to toggle source
# File lib/daigaku/solution.rb, line 52 def store_state=(verified) @verified = verified QuickStore.store.set(store_key, verified?) end