Sha256: 090cb881507de408e172ae590c980c762e86104cb2014216607486f19cb9f22e

Contents?: true

Size: 975 Bytes

Versions: 11

Compression:

Stored size: 975 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-0.11.1 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.11.0 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.10.0 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.9.0 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.8.3 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.8.2 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.8.1 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.8.0 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.7.0 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.6.1 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb
slack-ruby-bot-server-0.6.0 lib/slack-ruby-bot-server/api/presenters/status_presenter.rb