class BeatDB
  @@db_root = '/www/beatdb'
  
  def self.get key
    unless self.exists(key) || File.readable?(self.filePathByKey(key))
      return false
    end
    h = File.open(self.filePathByKey(key), 'r')
    JSON.decode(h.readline)
  end
  
  def self.set key, data
    unless self.exists(key) || File.writable?(self.filePathByKey(key))
      return false
    end
    h = File.open(self.filePathByKey(key), 'w')
    h.puts(JSON.encode(data))
  end
  
  def self.delete key
    
  end
  
  def self.exists key
    File.exists?(self.filePathByKey(key))
  end
  
  def self.filePathByKey key
    path = ''
    key.to_s.each_char {|c| path << '/' + c}
    @@db_root + path[0..(path.length-2)] <<  key.to_s + '.json'
  end
end