Class: Exercism::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/exercism/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#fileObject (readonly)

Returns the value of attribute file.



15
16
17
# File 'lib/exercism/config.rb', line 15

def file
  @file
end

#github_usernameObject



22
23
24
# File 'lib/exercism/config.rb', line 22

def github_username
  @github_username ||= from_yaml['github_username']
end

#keyObject



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

#deleteObject



38
39
40
# File 'lib/exercism/config.rb', line 38

def delete
  FileUtils.rm(file) if File.exists?(file)
end

#saveObject



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