Module: Babik::QuerySet::Countable

Included in:
AbstractBase
Defined in:
lib/babik/queryset/mixins/countable.rb

Overview

Functionality related to the size of the QuerySet

Instance Method Summary collapse

Instance Method Details

#countInteger

Return the number of elements that match the condition defined by successive calls of filter and exclude.

Returns:

  • (Integer)

    Number of elements that match the condition defined in this QuerySet.



10
11
12
# File 'lib/babik/queryset/mixins/countable.rb', line 10

def count
  self.all.count
end

#empty?Boolean

Inform if the QuerySet has no elements that match the condition.

Returns:

  • (Boolean)

    True if no records match the filter, false otherwise.



16
17
18
# File 'lib/babik/queryset/mixins/countable.rb', line 16

def empty?
  self.count.zero?
end

#exists?Boolean

Inform if the QuerySet has at least one element that match the condition.

Returns:

  • (Boolean)

    True if one or more records match the filter, false otherwise.



22
23
24
# File 'lib/babik/queryset/mixins/countable.rb', line 22

def exists?
  self.count.positive?
end

#lengthInteger

Return the number of elements that match the condition defined by successive calls of filter and exclude. Alias of count.

Returns:

  • (Integer)

    Number of elements that match the condition defined in this QuerySet.

See Also:



30
31
32
# File 'lib/babik/queryset/mixins/countable.rb', line 30

def length
  self.count
end

#sizeInteger

Return the number of elements that match the condition defined by successive calls of filter and exclude. Alias of count.

Returns:

  • (Integer)

    Number of elements that match the condition defined in this QuerySet.

See Also:



38
39
40
# File 'lib/babik/queryset/mixins/countable.rb', line 38

def size
  self.count
end