class Exercism::Config
Attributes
github_username[W]
key[W]
path[R]
project_dir[W]
Public Class Methods
alternate_path()
click to toggle source
# File lib/exercism/config.rb, line 6 def self.alternate_path File.join(Env.home, '.config') end
new(path)
click to toggle source
# File lib/exercism/config.rb, line 26 def initialize(path) @path = path end
read(path)
click to toggle source
# File lib/exercism/config.rb, line 10 def self.read(path) config = new(path) config.exists? ? config : new(alternate_path) end
write(path, data)
click to toggle source
# 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
Public Instance Methods
delete()
click to toggle source
# File lib/exercism/config.rb, line 49 def delete FileUtils.rm(file) if exists? end
exists?()
click to toggle source
# File lib/exercism/config.rb, line 53 def exists? File.exists?(file) end
file()
click to toggle source
# File lib/exercism/config.rb, line 57 def file @file ||= File.join(path, filename) end
github_username()
click to toggle source
# File lib/exercism/config.rb, line 30 def github_username @github_username ||= from_yaml['github_username'] end
key()
click to toggle source
# File lib/exercism/config.rb, line 34 def key @key ||= from_yaml['key'] end
project_dir()
click to toggle source
# File lib/exercism/config.rb, line 38 def project_dir @project_dir ||= from_yaml['project_dir'] end
save()
click to toggle source
# File lib/exercism/config.rb, line 42 def save FileUtils.mkdir_p(project_dir) FileUtils.mkdir_p(path) save_to_file self end
Private Instance Methods
default?()
click to toggle source
# File lib/exercism/config.rb, line 85 def default? path !~ /\.config/ end
filename()
click to toggle source
# File lib/exercism/config.rb, line 81 def filename default? ? ".exercism" : "exercism" end
from_yaml()
click to toggle source
# File lib/exercism/config.rb, line 89 def from_yaml @data ||= store.load(File.read(file)) unless @data raise StandardError.new "Cannot read #{file}" end @data end
save_to_file()
click to toggle source
# File lib/exercism/config.rb, line 63 def save_to_file data = { 'github_username' => github_username, 'key' => key, 'project_dir' => project_dir } store.transaction do data.each_pair do |k,v| store[k] = v end end end
store()
click to toggle source
# File lib/exercism/config.rb, line 77 def store @store ||= YAML::Store.new(file) end