Method: Restforce::Collection#count

Defined in:
lib/restforce/collection.rb

#count(*args) ⇒ Object

[View source]

42
43
44
45
46
47
48
49
50
51
52
# File 'lib/restforce/collection.rb', line 42

def count(*args)
  # By default, `Enumerable`'s `#count` uses `#each`, which means going through all
  # of the pages of results, one by one. Instead, we can use `#size` which we have
  # already overridden to work in a smarter, more efficient way. This only works for
  # the simple version of `#count` with no arguments. When called with an argument or
  # a block, you need to know what the items in the collection actually are, so we
  # call `super` and end up iterating through each item in the collection.
  return size unless block_given? || !args.empty?

  super
end