module Babik::QuerySet::Countable

Functionality related to the size of the QuerySet

Public Instance Methods

count() click to toggle source

Return the number of elements that match the condition defined by successive calls of filter and exclude. @return [Integer] Number of elements that match the condition defined in this QuerySet.

# File lib/babik/queryset/mixins/countable.rb, line 10
def count
  self.all.count
end
empty?() click to toggle source

Inform if the QuerySet has no elements that match the condition. @return [Boolean] True if no records match the filter, false otherwise.

# File lib/babik/queryset/mixins/countable.rb, line 16
def empty?
  self.count.zero?
end
exists?() click to toggle source

Inform if the QuerySet has at least one element that match the condition. @return [Boolean] True if one or more records match the filter, false otherwise.

# File lib/babik/queryset/mixins/countable.rb, line 22
def exists?
  self.count.positive?
end
length() click to toggle source

Return the number of elements that match the condition defined by successive calls of filter and exclude. Alias of count. @see Babik::QuerySet::Countable#count @return [Integer] Number of elements that match the condition defined in this QuerySet.

# File lib/babik/queryset/mixins/countable.rb, line 30
def length
  self.count
end
size() click to toggle source

Return the number of elements that match the condition defined by successive calls of filter and exclude. Alias of count. @see Babik::QuerySet::Countable#count @return [Integer] Number of elements that match the condition defined in this QuerySet.

# File lib/babik/queryset/mixins/countable.rb, line 38
def size
  self.count
end