class Xray::Config
Constants
- CONFIG_FILE
Public Instance Methods
config_file()
click to toggle source
# File lib/xray/config.rb, line 34 def config_file if File.exist?("#{Dir.pwd}/#{CONFIG_FILE}") "#{Dir.pwd}/#{CONFIG_FILE}" else "#{Dir.home}/#{CONFIG_FILE}" end end
default_editor()
click to toggle source
# File lib/xray/config.rb, line 10 def default_editor ENV['GEM_EDITOR'] || ENV['VISUAL'] || ENV['EDITOR'] || '/usr/local/bin/subl' end
editor()
click to toggle source
# File lib/xray/config.rb, line 17 def editor load_config[:editor] end
editor=(new_editor)
click to toggle source
# File lib/xray/config.rb, line 21 def editor=(new_editor) if new_editor && new_editor != editor write_config(editor: new_editor) true else false end end
to_yaml()
click to toggle source
# File lib/xray/config.rb, line 30 def to_yaml {editor: editor}.to_yaml end
Private Instance Methods
default_config()
click to toggle source
# File lib/xray/config.rb, line 59 def default_config { editor: default_editor } end
load_config()
click to toggle source
# File lib/xray/config.rb, line 49 def load_config default_config.merge(local_config) end
local_config()
click to toggle source
# File lib/xray/config.rb, line 53 def local_config YAML.load_file(config_file) rescue {} end
write_config(new_config)
click to toggle source
# File lib/xray/config.rb, line 44 def write_config(new_config) config = load_config.merge(new_config) File.open(config_file, 'w') { |f| f.write(config.to_yaml) } end