class ET::Config
Attributes
current_dir[R]
Public Class Methods
new(current_dir)
click to toggle source
# File lib/et/config.rb, line 8 def initialize(current_dir) @current_dir = current_dir end
Public Instance Methods
[](key)
click to toggle source
# File lib/et/config.rb, line 36 def [](key) options[key] end
exists?()
click to toggle source
# File lib/et/config.rb, line 32 def exists? !path.nil? end
host()
click to toggle source
# File lib/et/config.rb, line 16 def host if options["host"].start_with?("http") options["host"] else "http://" + options["host"] end end
path()
click to toggle source
# File lib/et/config.rb, line 12 def path @path ||= find_config_file(current_dir) end
save!(options)
click to toggle source
# File lib/et/config.rb, line 40 def save!(options) if exists? File.write(path, options.to_yaml) else File.write(File.join(current_dir, ".et"), options.to_yaml) end end
token()
click to toggle source
# File lib/et/config.rb, line 28 def token options["token"] end
username()
click to toggle source
# File lib/et/config.rb, line 24 def username options["username"] end
Private Instance Methods
find_config_file(dir)
click to toggle source
# File lib/et/config.rb, line 54 def find_config_file(dir) config_path = File.join(dir, ".et") if File.exists?(config_path) config_path elsif dir == "." || Pathname.new(dir).root? nil else find_config_file(File.dirname(dir)) end end
options()
click to toggle source
# File lib/et/config.rb, line 50 def options @options ||= YAML.load(File.read(path)) end