Class: Daigaku::Configuration
- Inherits:
-
Object
- Object
- Daigaku::Configuration
- Includes:
- Singleton
- Defined in:
- lib/daigaku/configuration.rb
Constant Summary collapse
- LOCAL_DIR =
'.daigaku'- COURSES_DIR =
'courses'- SOLUTIONS_DIR =
'solutions'- STORAGE_FILE =
'daigaku.db.yml'- DAIGAKU_INITIAL_COURSE =
'daigaku-ruby/Get_started_with_Ruby'
Instance Attribute Summary collapse
-
#courses_path ⇒ Object
Returns the value of attribute courses_path.
-
#storage_file ⇒ Object
readonly
Returns the value of attribute storage_file.
Instance Method Summary collapse
- #import! ⇒ Object
- #initial_course ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #save ⇒ Object
- #solutions_path ⇒ Object
- #solutions_path=(path) ⇒ Object
- #summary ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
17 18 19 20 21 22 23 24 25 26 |
# 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 |
Instance Attribute Details
#courses_path ⇒ Object
Returns the value of attribute courses_path.
14 15 16 |
# File 'lib/daigaku/configuration.rb', line 14 def courses_path @courses_path end |
#storage_file ⇒ Object (readonly)
Returns the value of attribute storage_file.
15 16 17 |
# File 'lib/daigaku/configuration.rb', line 15 def storage_file @storage_file end |
Instance Method Details
#import! ⇒ Object
58 59 60 61 62 |
# File 'lib/daigaku/configuration.rb', line 58 def import! @courses_path = QuickStore.store.courses_path || @courses_path @solutions_path = QuickStore.store.solutions_path || @solutions_path self end |
#initial_course ⇒ Object
77 78 79 |
# File 'lib/daigaku/configuration.rb', line 77 def initial_course DAIGAKU_INITIAL_COURSE end |
#save ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/daigaku/configuration.rb', line 47 def save settings = self.instance_variables settings.delete(:@storage_file) settings.each do |variable| key = variable.to_s.delete('@') value = self.instance_variable_get(variable.to_sym) QuickStore.store.set(key, value) end end |
#solutions_path ⇒ Object
28 29 30 |
# File 'lib/daigaku/configuration.rb', line 28 def solutions_path @solutions_path || raise(Daigaku::ConfigurationError, 'Solutions path is not set.') end |
#solutions_path=(path) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/daigaku/configuration.rb', line 32 def solutions_path=(path) full_path = File.(path, Dir.pwd) unless Dir.exist?(full_path) error = [ Daigaku::ConfigurationError, "Solutions path \"#{path}\" isn't an existing directory." ] raise(*error) end @solutions_path = full_path end |
#summary ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/daigaku/configuration.rb', line 64 def summary settings = self.instance_variables settings.delete(:@storage_file) lines = settings.map do |variable| key = variable.to_s.delete('@').gsub('_', ' ') value = self.instance_variable_get(variable.to_sym) "* #{key}: #{value}" end lines.join("\n") end |