Module: SnowmanIO::API::Extra::Meteor

Defined in:
lib/snowman-io/api/extra/meteor.rb

Overview

Simple and a little bit ugly web sockets replacement

Class Method Summary collapse

Class Method Details

.all(last) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/snowman-io/api/extra/meteor.rb', line 6

def self.all(last)
  at = Time.at(last)
  now = Time.now

  if last == 0
    {
      users: User.all,
      apps: App.all,
      metrics: Metric.all,
      checks: Check.all,
      users_deleted: [],
      apps_deleted: [],
      metrics_deleted: [],
      checks_deleted: [],
      last: now.to_i,
      version: (ENV["DEV_MODE"].to_i == 1 ? "__VERSION__" : SnowmanIO::VERSION)
    }
  else
    scope = Deleted.where(:created_at.gte => at)
    {
      users: User.where(:updated_at.gte => at),
      apps: App.where(:updated_at.gte => at),
      metrics: Metric.where(:updated_at.gte => at),
      checks: Check.where(:updated_at.gte => at),
      users_deleted: scope.where(model_kind: User.to_s).map(&:model_id),
      apps_deleted: scope.where(model_kind: App.to_s).map(&:model_id),
      metrics_deleted: scope.where(model_kind: Metric.to_s).map(&:model_id),
      checks_deleted: scope.where(model_kind: Check.to_s).map(&:model_id),
      last: now.to_i,
      version: (ENV["DEV_MODE"].to_i == 1 ? "__VERSION__" : SnowmanIO::VERSION)
    }
  end
end

.model_destroy(record) ⇒ Object



40
41
42
43
# File 'lib/snowman-io/api/extra/meteor.rb', line 40

def self.model_destroy(record)
  Deleted.create!(model_kind: record.class.to_s, model_id: record.id.to_s)
  record.destroy
end