Class: Exercism::Config
- Inherits:
-
Object
- Object
- Exercism::Config
- Defined in:
- lib/exercism/config.rb
Instance Attribute Summary collapse
- #github_username ⇒ Object
- #key ⇒ Object
-
#path ⇒ Object
readonly
Returns the value of attribute path.
- #project_dir ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
- #exists? ⇒ Boolean
- #file ⇒ Object
-
#initialize(path) ⇒ Config
constructor
A new instance of Config.
- #save ⇒ Object
Constructor Details
#initialize(path) ⇒ Config
Returns a new instance of Config.
26 27 28 |
# File 'lib/exercism/config.rb', line 26 def initialize(path) @path = path end |
Instance Attribute Details
#github_username ⇒ Object
30 31 32 |
# File 'lib/exercism/config.rb', line 30 def github_username @github_username ||= from_yaml['github_username'] end |
#key ⇒ Object
34 35 36 |
# File 'lib/exercism/config.rb', line 34 def key @key ||= from_yaml['key'] end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
23 24 25 |
# File 'lib/exercism/config.rb', line 23 def path @path end |
#project_dir ⇒ Object
38 39 40 |
# File 'lib/exercism/config.rb', line 38 def project_dir @project_dir ||= from_yaml['project_dir'] end |
Class Method Details
.alternate_path ⇒ Object
6 7 8 |
# File 'lib/exercism/config.rb', line 6 def self.alternate_path File.join(Env.home, '.config') end |
.read(path) ⇒ Object
10 11 12 13 |
# File 'lib/exercism/config.rb', line 10 def self.read(path) config = new(path) config.exists? ? config : new(alternate_path) end |
.write(path, data) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/exercism/config.rb', line 15 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
49 50 51 |
# File 'lib/exercism/config.rb', line 49 def delete FileUtils.rm(file) if exists? end |
#exists? ⇒ Boolean
53 54 55 |
# File 'lib/exercism/config.rb', line 53 def exists? File.exists?(file) end |
#file ⇒ Object
57 58 59 |
# File 'lib/exercism/config.rb', line 57 def file @file ||= File.join(path, filename) end |
#save ⇒ Object
42 43 44 45 46 47 |
# File 'lib/exercism/config.rb', line 42 def save FileUtils.mkdir_p(project_dir) FileUtils.mkdir_p(path) save_to_file self end |