You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
656B

  1. class Datastore
  2. @@client = Mongo::Client.new ENV['MONGO_URL']
  3. def self.host(type, host, port)
  4. key = self.key host, port
  5. @@client[type].find(key).first
  6. # result = @@index.type(type).get key
  7. # result.date = Time.parse result.date
  8. # result
  9. end
  10. def self.pending(type, host, port)
  11. self.post type, host, port, { pending: true, date: DateTime.now }
  12. end
  13. def self.post(type, host, port, data)
  14. # entry = self.host type, host, port
  15. # entry.delete if entry
  16. #
  17. key = self.key host, port
  18. data = data.merge key
  19. @@client[type].update_one key, data, {upsert: true}
  20. end
  21. private
  22. def self.key(host, port)
  23. { host: host, port: port }
  24. end
  25. end