Class: NewlineHw::Config

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

Constant Summary collapse

CONFIG_PATH =
File.expand_path("~/.newline_hw.yaml").freeze
DEFAULTS =
{
  "editor" => "atom",
  "terminal" => "Terminal",
  "launch_editor" => true,
  "homework_dir" => "~/theironyard/homework",
  "log_file" => "~/Library/Logs/newline_hw/newlinehw.log"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.install_defaultObject



48
49
50
51
52
# File 'lib/newline_hw/config.rb', line 48

def self.install_default
  File.open(CONFIG_PATH, "w+") do |f|
    f.write DEFAULTS.to_yaml
  end
end

Instance Method Details

#configObject



18
19
20
# File 'lib/newline_hw/config.rb', line 18

def config
  @config ||= DEFAULTS.merge(config_file)
end

#config_fileObject



22
23
24
25
26
# File 'lib/newline_hw/config.rb', line 22

def config_file
  YAML.load_file(CONFIG_PATH) || DEFAULTS
rescue Errno::ENOENT
  DEFAULTS
end

#editorObject



28
29
30
# File 'lib/newline_hw/config.rb', line 28

def editor
  config["editor"]
end

#homework_dirObject



40
41
42
# File 'lib/newline_hw/config.rb', line 40

def homework_dir
  config["homework_dir"]
end

#launch_editorObject



44
45
46
# File 'lib/newline_hw/config.rb', line 44

def launch_editor
  config["launch_editor"]
end

#log_fileObject



36
37
38
# File 'lib/newline_hw/config.rb', line 36

def log_file
  config["log_file"]
end

#terminalObject



32
33
34
# File 'lib/newline_hw/config.rb', line 32

def terminal
  config["terminal"]
end

#update(options) ⇒ Object



14
15
16
# File 'lib/newline_hw/config.rb', line 14

def update(options)
  @config = config.merge(options)
end