class EY::EYRC

Constants

DEFAULT_PATH

Attributes

path[R]

Public Class Methods

load() click to toggle source
# File lib/engineyard/eyrc.rb, line 7
def self.load
  new(ENV['EYRC'] || DEFAULT_PATH)
end
new(path) click to toggle source
# File lib/engineyard/eyrc.rb, line 11
def initialize(path)
  @path = Pathname.new(path).expand_path
end

Public Instance Methods

api_token() click to toggle source
# File lib/engineyard/eyrc.rb, line 23
def api_token
  self['api_token']
end
api_token=(token) click to toggle source
# File lib/engineyard/eyrc.rb, line 27
def api_token=(token)
  self['api_token'] = token
end
delete_api_token() click to toggle source
# File lib/engineyard/eyrc.rb, line 19
def delete_api_token
  delete('api_token')
end
exist?() click to toggle source
# File lib/engineyard/eyrc.rb, line 15
def exist?
  path.exist?
end

Private Instance Methods

[](key) click to toggle source
# File lib/engineyard/eyrc.rb, line 33
def [](key)
  read_data[key.to_s]
end
[]=(key,val) click to toggle source
# File lib/engineyard/eyrc.rb, line 37
def []=(key,val)
  new_data = read_data.merge(key.to_s => val)
  write_data new_data
  val
end
delete(key) click to toggle source
# File lib/engineyard/eyrc.rb, line 43
def delete(key)
  data = read_data.dup
  res = data.delete(key)
  write_data data
  res
end
read_data() click to toggle source
# File lib/engineyard/eyrc.rb, line 50
def read_data
  exist? && YAML.load(path.read) || {}
end
write_data(new_data) click to toggle source
# File lib/engineyard/eyrc.rb, line 54
def write_data(new_data)
  path.open("w") {|f| YAML.dump(new_data, f) }
end