Class: Exercism::Config
- Inherits:
-
Object
- Object
- Exercism::Config
- Defined in:
- lib/exercism/config.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
- #github_username ⇒ Object
- #key ⇒ Object
- #project_dir ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(path) ⇒ Config
constructor
A new instance of Config.
- #save ⇒ Object
Constructor Details
#initialize(path) ⇒ Config
Returns a new instance of Config.
19 20 21 |
# File 'lib/exercism/config.rb', line 19 def initialize(path) @file = File.join(path, '.exercism') end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
16 17 18 |
# File 'lib/exercism/config.rb', line 16 def file @file end |
#github_username ⇒ Object
23 24 25 |
# File 'lib/exercism/config.rb', line 23 def github_username @github_username ||= from_yaml['github_username'] end |
#key ⇒ Object
27 28 29 |
# File 'lib/exercism/config.rb', line 27 def key @key ||= from_yaml['key'] end |
#project_dir ⇒ Object
31 32 33 |
# File 'lib/exercism/config.rb', line 31 def project_dir @project_dir ||= from_yaml['project_dir'] end |
Class Method Details
.read(path) ⇒ Object
4 5 6 |
# File 'lib/exercism/config.rb', line 4 def self.read(path) new(path) end |
.write(path, data) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/exercism/config.rb', line 8 def self.write(path, data) config = new(path) config.github_username = data['github_username'] config.key = data['key'] config.project_dir = data['project_dir'] config.save end |
Instance Method Details
#delete ⇒ Object
48 49 50 |
# File 'lib/exercism/config.rb', line 48 def delete FileUtils.rm(file) if File.exists?(file) end |
#save ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/exercism/config.rb', line 35 def save FileUtils.mkdir_p(project_dir) File.open file, 'w' do |f| data = { 'github_username' => github_username, 'key' => key, 'project_dir' => project_dir } f.write data.to_yaml end self end |