Module: Quo::ComposedQuery
- Defined in:
- lib/quo/composed_query.rb,
sig/generated/quo/composed_query.rbs
Overview
Mixin for queries composed of two child queries
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #both_relations?(left, right) ⇒ Boolean
- #child_options(query_class) ⇒ Hash[Symbol, untyped]
- #inspect ⇒ void
- #is_relation?(rel) ⇒ Boolean
- #left ⇒ Quo::Query, ::ActiveRecord::Relation
- #left_enumerable_right_relation?(left, right) ⇒ Boolean
- #left_relation_right_enumerable?(left, right) ⇒ Boolean
- #merge_active_record_relations(left_rel, right_rel) ⇒ ActiveRecord::Relation
- #merge_left_and_right ⇒ ActiveRecord::Relation, CollectionBackedQuery
- #property_names(query_class) ⇒ Array[Symbol]
- #query ⇒ void
- #right ⇒ Quo::Query, ::ActiveRecord::Relation
Class Method Details
.included(base) ⇒ void
This method returns an undefined value.
41 42 43 |
# File 'lib/quo/composed_query.rb', line 41 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#both_relations?(left, right) ⇒ Boolean
125 126 127 |
# File 'lib/quo/composed_query.rb', line 125 def both_relations?(left, right) is_relation?(left) && is_relation?(right) end |
#child_options(query_class) ⇒ Hash[Symbol, untyped]
59 60 61 62 |
# File 'lib/quo/composed_query.rb', line 59 def (query_class) names = property_names(query_class) to_h.slice(*names) end |
#inspect ⇒ void
This method returns an undefined value.
51 52 53 54 |
# File 'lib/quo/composed_query.rb', line 51 def inspect klass_name = is_a?(Quo::RelationBackedQuery) ? Quo::RelationBackedQuery.name : Quo::CollectionBackedQuery.name "#{klass_name}<Quo::ComposedQuery>[#{self.class.quo_operand_desc(left.class)}, #{self.class.quo_operand_desc(right.class)}](#{super})" end |
#is_relation?(rel) ⇒ Boolean
118 119 120 |
# File 'lib/quo/composed_query.rb', line 118 def is_relation?(rel) rel.is_a?(::ActiveRecord::Relation) end |
#left ⇒ Quo::Query, ::ActiveRecord::Relation
70 71 72 73 74 75 76 77 |
# File 'lib/quo/composed_query.rb', line 70 def left lq = self.class._left_query return lq if is_relation?(lq) = (lq) spec = self.class._left_specification [:_specification] = spec if spec && lq < Quo::RelationBackedQuery lq.new(**) end |
#left_enumerable_right_relation?(left, right) ⇒ Boolean
139 140 141 |
# File 'lib/quo/composed_query.rb', line 139 def left_enumerable_right_relation?(left, right) !is_relation?(left) && is_relation?(right) end |
#left_relation_right_enumerable?(left, right) ⇒ Boolean
132 133 134 |
# File 'lib/quo/composed_query.rb', line 132 def left_relation_right_enumerable?(left, right) is_relation?(left) && !is_relation?(right) end |
#merge_active_record_relations(left_rel, right_rel) ⇒ ActiveRecord::Relation
110 111 112 113 114 |
# File 'lib/quo/composed_query.rb', line 110 def merge_active_record_relations(left_rel, right_rel) joins = self.class._composing_joins left_rel = left_rel.joins(joins) if joins left_rel.merge(right_rel) end |
#merge_left_and_right ⇒ ActiveRecord::Relation, CollectionBackedQuery
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/quo/composed_query.rb', line 90 def merge_left_and_right left_rel = quo_unwrap_unpaginated_query(left) right_rel = quo_unwrap_unpaginated_query(right) if both_relations?(left_rel, right_rel) merge_active_record_relations(left_rel, right_rel) elsif left_relation_right_enumerable?(left_rel, right_rel) left_rel.to_a + right_rel elsif left_enumerable_right_relation?(left_rel, right_rel) && left_rel.respond_to?(:+) left_rel + right_rel.to_a elsif left_rel.respond_to?(:+) left_rel + right_rel else raise ArgumentError, "Cannot merge #{left.class} with #{right.class}" end end |
#property_names(query_class) ⇒ Array[Symbol]
65 66 67 |
# File 'lib/quo/composed_query.rb', line 65 def property_names(query_class) query_class.literal_properties.properties_index.keys end |
#query ⇒ void
This method returns an undefined value.
46 47 48 |
# File 'lib/quo/composed_query.rb', line 46 def query merge_left_and_right end |
#right ⇒ Quo::Query, ::ActiveRecord::Relation
80 81 82 83 84 85 86 87 |
# File 'lib/quo/composed_query.rb', line 80 def right rq = self.class._right_query return rq if is_relation?(rq) = (rq) spec = self.class._right_specification [:_specification] = spec if spec && rq < Quo::RelationBackedQuery rq.new(**) end |