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.



26
27
28
# File 'lib/exercism/config.rb', line 26

def initialize(path)
  @path = path
end

Instance Attribute Details

#github_usernameObject



30
31
32
# File 'lib/exercism/config.rb', line 30

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

#keyObject



34
35
36
# File 'lib/exercism/config.rb', line 34

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

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#project_dirObject



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

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

Class Method Details

.alternate_pathObject



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

#deleteObject



49
50
51
# File 'lib/exercism/config.rb', line 49

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

#exists?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/exercism/config.rb', line 53

def exists?
  File.exists?(file)
end

#fileObject



57
58
59
# File 'lib/exercism/config.rb', line 57

def file
  @file ||= File.join(path, filename)
end

#saveObject



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