debian-mirror-gitlab/lib/gitlab/graphql/pagination/keyset/conditions/base_condition.rb

59 lines
1.9 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
module Gitlab
module Graphql
2020-04-22 19:07:51 +05:30
module Pagination
2019-12-26 22:10:19 +05:30
module Keyset
module Conditions
class BaseCondition
2020-03-13 15:44:24 +05:30
# @param [Arel::Table] arel_table for the relation being ordered
# @param [Array<OrderInfo>] order_list of extracted orderings
# @param [Array] values from the decoded cursor
# @param [Array<String>] operators determining sort comparison
# @param [Symbol] before_or_after indicates whether we want
# items :before the cursor or :after the cursor
def initialize(arel_table, order_list, values, operators, before_or_after)
@arel_table, @order_list, @values, @operators, @before_or_after = arel_table, order_list, values, operators, before_or_after
@before_or_after = :after unless [:after, :before].include?(@before_or_after)
2019-12-26 22:10:19 +05:30
end
def build
raise NotImplementedError
end
private
2020-03-13 15:44:24 +05:30
attr_reader :arel_table, :order_list, :values, :operators, :before_or_after
def table_condition(order_info, value, operator)
if order_info.named_function
target = order_info.named_function
2020-11-24 15:15:51 +05:30
if target.try(:name)&.casecmp('lower') == 0
value = value&.downcase
end
2020-03-13 15:44:24 +05:30
else
target = arel_table[order_info.attribute_name]
end
2019-12-26 22:10:19 +05:30
case operator
when '>'
2020-03-13 15:44:24 +05:30
target.gt(value)
2019-12-26 22:10:19 +05:30
when '<'
2020-03-13 15:44:24 +05:30
target.lt(value)
2019-12-26 22:10:19 +05:30
when '='
2020-03-13 15:44:24 +05:30
target.eq(value)
2019-12-26 22:10:19 +05:30
when 'is_null'
2020-03-13 15:44:24 +05:30
target.eq(nil)
2019-12-26 22:10:19 +05:30
when 'is_not_null'
2020-03-13 15:44:24 +05:30
target.not_eq(nil)
2019-12-26 22:10:19 +05:30
end
end
end
end
end
end
end
end