app/services/schemas/orderings/order_builder/base.rb
# Build a case statement for sorting a boolean expression within an ordering.
#
# By default, we treat `true` values as coming before `false` values in ascending order,
# which is the opposite of PG's default (since false becomes 0 and true becomes 1 for sort purposes).
#
# However, if someone is building an ordering for their schemas, they probably want
# a boolean value pushed to the top when true by default most of the time, letting
# `ASC` be the default. If a user specifies `DESC` for the default sort order for
# the ordering, false will come first.
#
# @api private
# @param [Arel::Attribute, Arel::Nodes::Node] expression
# @param [Boolean] falsey_first
# @return [Arel::Nodes::Case]
Build a case statement for sorting a boolean expression within an ordering.
By default, we treat `true` values as coming before `false` values in ascending order,
which is the opposite of PG's default (since false becomes 0 and true becomes 1 for sort purposes).

However, if someone is building an ordering for their schemas, they probably want
a boolean value pushed to the top when true by default most of the time, letting
`ASC` be the default. If a user specifies `DESC` for the default sort order for
the ordering, false will come first.
Build a case statement for sorting a boolean expression within an ordering . By default we treat ` true ` values as coming before ` false ` values in ascending order which is the opposite of PG ' s default ( since false becomes 0 and true becomes 1 for sort purposes ) . However if someone is building an ordering for their schemas they probably want a boolean value pushed to the top when true by default most of the time letting ` ASC ` be the default . If a user specifies ` DESC ` for the default sort order for the ordering false will come first .
def order_boolean(expression, falsey_first: false)
          truthy = falsey_first ? 1 : 0
          falsey = falsey_first ? 0 : 1
          Arel::Nodes::Case.new(expression).tap do |expr|
            expr.when(true).then(truthy)
            expr.when(false).then(falsey)
          end
        end
def order_boolean ( expression , falsey_first : false ) truthy = falsey_first ? 1 : 0 falsey = falsey_first ? 0 : 1 Arel :: Nodes :: Case . new ( expression ) . tap do | expr | expr . when ( true ) . then ( truthy ) expr . when ( false ) . then ( falsey ) end end
Build a case statement for sorting a boolean expression within an ordering.
Build a case statement for sorting a boolean expression within an ordering .
# :nocov: # :nocov:
None
Arel::Nodes::Case
expression
falsey_first
None
api
None