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
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.
18 19 20 |
# File 'lib/exercism/config.rb', line 18 def initialize(path) @file = File.join(path, '.exercism') end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
15 16 17 |
# File 'lib/exercism/config.rb', line 15 def file @file end |
#github_username ⇒ Object
22 23 24 |
# File 'lib/exercism/config.rb', line 22 def github_username @github_username ||= from_yaml['github_username'] end |
#key ⇒ Object
26 27 28 |
# File 'lib/exercism/config.rb', line 26 def key @key ||= from_yaml['key'] 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 |
# 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.save end |
Instance Method Details
#delete ⇒ Object
38 39 40 |
# File 'lib/exercism/config.rb', line 38 def delete FileUtils.rm(file) if File.exists?(file) end |
#save ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/exercism/config.rb', line 30 def save File.open file, 'w' do |f| data = {'github_username' => github_username, 'key' => key} f.write data.to_yaml end self end |