Sha256: b6cd0e2a1174babce63ebf782aeb33dba5f44b4e6af083f76214658f6e3369c0

Contents?: true

Size: 976 Bytes

Versions: 11

Compression:

Stored size: 976 Bytes

Contents

module SlackRubyBotServer
  module Api
    module Presenters
      module StatusPresenter
        include Roar::JSON::HAL
        include Roar::Hypermedia
        include Grape::Roar::Representer

        link :self do |opts|
          "#{base_url(opts)}/status"
        end

        property :teams_count
        property :active_teams_count
        property :ping

        def ping
          if SlackRubyBotServer::Config.mongoid?
            team = Team.asc(:_id).first
          elsif SlackRubyBotServer::Config.activerecord?
            team = Team.last
          else
            raise 'Unsupported database driver.'
          end
          return unless team

          team.ping!
        end

        def teams_count
          Team.count
        end

        def active_teams_count
          Team.active.count
        end

        def base_url(opts)
          request = Grape::Request.new(opts[:env])
          request.base_url
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
slack-ruby-bot-server-2.1.1 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-2.1.0 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-2.0.1 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-1.2.1 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-1.2.0 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-1.1.0 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-1.0.0 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.12.3 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.12.2 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.12.1 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.12.0 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb