Sha256: 70be55a03e9e9415c773213f5c5e9656c3e33eb73c799429edad9165be1bf2ec

Contents?: true

Size: 904 Bytes

Versions: 7

Compression:

Stored size: 904 Bytes

Contents

# frozen_string_literal: true

#
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module Dbee
  module Providers
    class ActiveRecordProvider
      class ExpressionBuilder
        # Derives Arel#order predicates.
        class OrderMaker
          include Singleton

          SORTER_EVALUATORS = {
            Query::Sorters::Ascending => ->(column) { column },
            Query::Sorters::Descending => ->(column) { column.desc }
          }.freeze

          private_constant :SORTER_EVALUATORS

          def make(sorter, arel_column)
            method = SORTER_EVALUATORS[sorter.class]

            raise ArgumentError, "cannot compile sorter: #{sorter}" unless method

            method.call(arel_column)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dbee-active_record-2.0.4 lib/dbee/providers/active_record_provider/expression_builder/order_maker.rb
dbee-active_record-2.0.3 lib/dbee/providers/active_record_provider/expression_builder/order_maker.rb
dbee-active_record-2.0.2 lib/dbee/providers/active_record_provider/expression_builder/order_maker.rb
dbee-active_record-2.0.1 lib/dbee/providers/active_record_provider/expression_builder/order_maker.rb
dbee-active_record-2.0.0 lib/dbee/providers/active_record_provider/expression_builder/order_maker.rb
dbee-active_record-2.0.0.pre.alpha lib/dbee/providers/active_record_provider/expression_builder/order_maker.rb
dbee-active_record-1.2.0 lib/dbee/providers/active_record_provider/expression_builder/order_maker.rb