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.

datastore.rb 608B

1234567891011121314151617181920212223242526
  1. class Datastore
  2. @@index = Stretcher::Server.new(ENV['ES_URL']).index :cryptcheck
  3. @@index.create unless @@index.exists?
  4. def self.host(type, host, port)
  5. result = @@index.type(type).get self.key(host, port)
  6. result.date = Time.parse result.date
  7. result
  8. rescue Stretcher::RequestError::NotFound
  9. end
  10. def self.pending(type, host, port)
  11. self.post type, host, port, { pending: true }
  12. end
  13. def self.post(type, host, port, data)
  14. data[:date] = DateTime.now
  15. @@index.type(type).put self.key(host, port), data
  16. end
  17. private
  18. def self.key(host, port)
  19. host = "#{host}:#{port}" if port
  20. host
  21. end
  22. end