Module: ParamsReady::Parameter::GroupingLike
- Included in:
- Query::ArrayGrouping, Query::StructuredGrouping
- Defined in:
- lib/params_ready/query/grouping.rb
Instance Method Summary collapse
- #eligible_for_query?(_table, context) ⇒ Boolean
- #predicate_group(arel_table, context: Restriction.blanket_permission) ⇒ Object
- #test(record) ⇒ Object
- #to_query(arel_table, context: Restriction.blanket_permission) ⇒ Object
- #to_query_if_eligible(arel_table, context:) ⇒ Object
Instance Method Details
#eligible_for_query?(_table, context) ⇒ Boolean
70 71 72 73 74 |
# 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) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/params_ready/query/grouping.rb', line 56 def predicate_group(arel_table, context: Restriction.) 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) ⇒ Object
87 88 89 90 91 92 93 94 |
# 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) ⇒ Object
83 84 85 |
# File 'lib/params_ready/query/grouping.rb', line 83 def to_query(arel_table, context: Restriction.) self.predicate_group(arel_table, context: context) end |
#to_query_if_eligible(arel_table, context:) ⇒ Object
76 77 78 79 80 81 |
# 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 |