class Daigaku::Configuration
Constants
- COURSES_DIR
- DAIGAKU_INITIAL_COURSE
- LOCAL_DIR
- SOLUTIONS_DIR
- STORAGE_FILE
Attributes
courses_path[RW]
storage_file[R]
Public Class Methods
new() { || ... }
click to toggle source
# File lib/daigaku/configuration.rb, line 17 def initialize @courses_path = local_path_to(COURSES_DIR) @storage_file = local_path_to(STORAGE_FILE) QuickStore.configure do |config| config.file_path = @storage_file end yield if block_given? end
Public Instance Methods
import()
click to toggle source
# File lib/daigaku/configuration.rb, line 57 def import store = QuickStore.store @courses_path = store.courses_path || @courses_path @solutions_path = store.solutions_path || @solutions_path self end
initial_course()
click to toggle source
# File lib/daigaku/configuration.rb, line 75 def initial_course DAIGAKU_INITIAL_COURSE end
save()
click to toggle source
# File lib/daigaku/configuration.rb, line 46 def save settings = instance_variables settings.delete(:@storage_file) settings.each do |variable| key = variable.to_s.delete('@') value = instance_variable_get(variable.to_sym) QuickStore.store.set(key, value) end end
solutions_path()
click to toggle source
# File lib/daigaku/configuration.rb, line 28 def solutions_path @solutions_path || raise(Daigaku::ConfigurationError, 'Solutions path is not set.') end
solutions_path=(path)
click to toggle source
# File lib/daigaku/configuration.rb, line 33 def solutions_path=(path) full_path = File.expand_path(path, Dir.pwd) unless Dir.exist?(full_path) raise( Daigaku::ConfigurationError, "Solutions path \"#{path}\" isn’t an existing directory." ) end @solutions_path = full_path end
summary()
click to toggle source
# File lib/daigaku/configuration.rb, line 64 def summary settings = instance_variables settings.delete(:@storage_file) settings.reduce('') do |lines, variable| key = variable.to_s.delete('@').tr('_', ' ') value = instance_variable_get(variable.to_sym) lines + "* #{key}: #{value}\n" end end
Private Instance Methods
local_path_to(*resource)
click to toggle source
# File lib/daigaku/configuration.rb, line 81 def local_path_to(*resource) path = File.join('~', LOCAL_DIR, resource) File.expand_path(path, __FILE__) end