module ParamsReady::Parameter::GroupingLike
Public Instance Methods
eligible_for_query?(_table, context)
click to toggle source
# File lib/params_ready/query/grouping.rb, line 70 def eligible_for_query?(_table, context) return false unless context.permitted? self is_definite? end
predicate_group(arel_table, context: Restriction.blanket_permission)
click to toggle source
# File lib/params_ready/query/grouping.rb, line 56 def predicate_group(arel_table, context: Restriction.blanket_permission) subqueries = predicates.reduce(nil) do |acc, predicate| query = predicate.to_query_if_eligible(arel_table, context: context) # This duplicates the operator logic # but we want operator to be optional # for single predicate groupings next query if acc.nil? operator.connect(acc, query) end return nil if subqueries.nil? arel_table.grouping(subqueries) end
test(record)
click to toggle source
# File lib/params_ready/query/grouping.rb, line 87 def test(record) return nil unless is_definite? predicates = self.predicates return nil if predicates.empty? operator.test(record, predicates) end
to_query(arel_table, context: Restriction.blanket_permission)
click to toggle source
# File lib/params_ready/query/grouping.rb, line 83 def to_query(arel_table, context: Restriction.blanket_permission) self.predicate_group(arel_table, context: context) end
to_query_if_eligible(arel_table, context:)
click to toggle source
# File lib/params_ready/query/grouping.rb, line 76 def to_query_if_eligible(arel_table, context:) return nil unless eligible_for_query?(arel_table, context) context = context_for_predicates(context) to_query(arel_table, context: context) end