Class: ActiveAdmin::AsyncCount

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/async_count.rb

Defined Under Namespace

Classes: NotSupportedError

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ AsyncCount

Returns a new instance of AsyncCount.

Raises:



6
7
8
9
10
11
# File 'lib/active_admin/async_count.rb', line 6

def initialize(collection)
  raise NotSupportedError, "#{collection.inspect} does not support :async_count" unless collection.respond_to?(:async_count)

  @collection = collection.except(:select, :order)
  @promise = @collection.async_count
end

Instance Method Details

#countObject Also known as: size



13
14
15
16
17
# File 'lib/active_admin/async_count.rb', line 13

def count
  value = @promise.value
  # value.value due to Rails bug https://github.com/rails/rails/issues/50776
  value.respond_to?(:value) ? value.value : value
end