Sha256: fe3394acc85177ac6d2a40c0bebc59edbf2def0938ff3fc878b2632bf4111364

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

module SnowmanIO
  module API
    module Extra
      # Simple and a little bit ugly web sockets replacement
      module Meteor
        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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
snowman-io-0.5.1 lib/snowman-io/api/extra/meteor.rb
snowman-io-0.5.0 lib/snowman-io/api/extra/meteor.rb
snowman-io-0.4.0 lib/snowman-io/api/extra/meteor.rb
snowman-io-0.3.1 lib/snowman-io/api/extra/meteor.rb
snowman-io-0.3.0 lib/snowman-io/api/extra/meteor.rb