class ActiveRecord::Relation::WhereClause
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/active_record/relation/where_clause.rbs class ActiveRecord::Relation::WhereClause def self.empty: () -> untyped def +: (ActiveRecord::Relation::WhereClause other) -> ActiveRecord::Relation::WhereClause def -: (ActiveRecord::Relation::WhereClause other) -> untyped def each_attributes: () -> untyped def extract_attribute: (Arel::Nodes::Equality node) -> Arel::Attributes::Attribute def initialize: ((Array[Arel::Nodes::Equality] | Array[]) predicates) -> void def merge: (ActiveRecord::Relation::WhereClause other, ?nil rewhere) -> untyped def non_empty_predicates: () -> untyped def predicates_unreferenced_by: (ActiveRecord::Relation::WhereClause other) -> untyped def predicates_with_wrapped_sql_literals: () -> untyped def referenced_columns: () -> untyped end
:nodoc:
def self.empty
Experimental RBS support (using type sampling data from the type_fusion
project).
def self.empty: () -> untyped
This signature was generated using 14 samples from 1 application.
def self.empty @empty ||= new([]).freeze end
def +(other)
Experimental RBS support (using type sampling data from the type_fusion
project).
def +: (ActiveRecord::Relation::WhereClause other) -> ActiveRecord::Relation::WhereClause
This signature was generated using 8 samples from 1 application.
def +(other) WhereClause.new(predicates + other.predicates) end
def -(other)
Experimental RBS support (using type sampling data from the type_fusion
project).
def -: (ActiveRecord::Relation::WhereClause other) -> untyped
This signature was generated using 1 sample from 1 application.
def -(other) WhereClause.new(predicates - other.predicates) end
def ==(other)
def ==(other) other.is_a?(WhereClause) && predicates == other.predicates end
def ast
def ast predicates = predicates_with_wrapped_sql_literals predicates.one? ? predicates.first : Arel::Nodes::And.new(predicates) end
def contradiction?
def contradiction? predicates.any? do |x| case x when Arel::Nodes::In Array === x.right && x.right.empty? when Arel::Nodes::Equality x.right.respond_to?(:unboundable?) && x.right.unboundable? end end end
def each_attributes
Experimental RBS support (using type sampling data from the type_fusion
project).
def each_attributes: () -> untyped
This signature was generated using 4 samples from 1 application.
def each_attributes predicates.each do |node| attr = extract_attribute(node) || begin node.left if equality_node?(node) && node.left.is_a?(Arel::Predications) end yield attr, node if attr end end
def equalities(predicates, equality_only)
def equalities(predicates, equality_only) equalities = [] predicates.each do |node| if equality_only ? Arel::Nodes::Equality === node : equality_node?(node) equalities << node elsif node.is_a?(Arel::Nodes::And) equalities.concat equalities(node.children, equality_only) end end equalities end
def equality_node?(node)
def equality_node?(node) !node.is_a?(String) && node.equality? end
def except(*columns)
def except(*columns) WhereClause.new(except_predicates(columns)) end
def except_predicates(columns)
def except_predicates(columns) attrs = columns.extract! { |node| node.is_a?(Arel::Attribute) } non_attrs = columns.extract! { |node| node.is_a?(Arel::Predications) } predicates.reject do |node| if !non_attrs.empty? && node.equality? && node.left.is_a?(Arel::Predications) non_attrs.include?(node.left) end || Arel.fetch_attribute(node) do |attr| attrs.include?(attr) || columns.include?(attr.name.to_s) end end end
def extract_attribute(node)
Experimental RBS support (using type sampling data from the type_fusion
project).
def extract_attribute: (Arel::Nodes::Equality node) -> Arel::Attributes::Attribute
This signature was generated using 6 samples from 1 application.
def extract_attribute(node) attr_node = nil Arel.fetch_attribute(node) do |attr| return if attr_node&.!= attr # all attr nodes should be the same attr_node = attr end attr_node end
def extract_attributes
def extract_attributes attrs = [] each_attributes { |attr, _| attrs << attr } attrs end
def extract_node_value(node)
def extract_node_value(node) if node.respond_to?(:value_before_type_cast) node.value_before_type_cast elsif Array === node node.map { |v| extract_node_value(v) } end end
def hash
def hash [self.class, predicates].hash end
def initialize(predicates)
Experimental RBS support (using type sampling data from the type_fusion
project).
type ActiveRecord__Relation__WhereClause_initialize_predicates = Arel::Nodes::Equality | Arel::Nodes::Equality | Arel::Nodes::Equality | Arel::Nodes::Grouping | | Arel::Nodes::Equality | Arel::Nodes::Equality def initialize: (ActiveRecord__Relation__WhereClause_initialize_predicates predicates) -> void
This signature was generated using 19 samples from 1 application.
def initialize(predicates) @predicates = predicates end
def invert
def invert if predicates.size == 1 inverted_predicates = [ invert_predicate(predicates.first) ] else inverted_predicates = [ Arel::Nodes::Not.new(ast) ] end WhereClause.new(inverted_predicates) end
def invert_predicate(node)
def invert_predicate(node) case node when NilClass raise ArgumentError, "Invalid argument for .where.not(), got nil." when String Arel::Nodes::Not.new(Arel::Nodes::SqlLiteral.new(node)) else node.invert end end
def merge(other, rewhere = nil)
Experimental RBS support (using type sampling data from the type_fusion
project).
def merge: (ActiveRecord::Relation::WhereClause other, ?nil rewhere) -> untyped
This signature was generated using 5 samples from 1 application.
def merge(other, rewhere = nil) predicates = if rewhere except_predicates(other.extract_attributes) else predicates_unreferenced_by(other) end WhereClause.new(predicates | other.predicates) end
def non_empty_predicates
Experimental RBS support (using type sampling data from the type_fusion
project).
def non_empty_predicates: () -> untyped
This signature was generated using 3 samples from 1 application.
def non_empty_predicates predicates - ARRAY_WITH_EMPTY_STRING end
def or(other)
def or(other) left = self - other common = self - left right = other - common if left.empty? || right.empty? common else left = left.ast left = left.expr if left.is_a?(Arel::Nodes::Grouping) right = right.ast right = right.expr if right.is_a?(Arel::Nodes::Grouping) or_clause = Arel::Nodes::Or.new(left, right) common.predicates << Arel::Nodes::Grouping.new(or_clause) common end end
def predicates_unreferenced_by(other)
Experimental RBS support (using type sampling data from the type_fusion
project).
def predicates_unreferenced_by: (ActiveRecord::Relation::WhereClause other) -> untyped
This signature was generated using 7 samples from 1 application.
def predicates_unreferenced_by(other) referenced_columns = other.referenced_columns predicates.reject do |node| attr = extract_attribute(node) || begin node.left if equality_node?(node) && node.left.is_a?(Arel::Predications) end attr && referenced_columns[attr] end end
def predicates_with_wrapped_sql_literals
Experimental RBS support (using type sampling data from the type_fusion
project).
def predicates_with_wrapped_sql_literals: () -> untyped
This signature was generated using 2 samples from 1 application.
def predicates_with_wrapped_sql_literals non_empty_predicates.map do |node| case node when Arel::Nodes::SqlLiteral, ::String wrap_sql_literal(node) else node end end end
def referenced_columns
Experimental RBS support (using type sampling data from the type_fusion
project).
def referenced_columns: () -> untyped
This signature was generated using 6 samples from 1 application.
def referenced_columns hash = {} each_attributes { |attr, node| hash[attr] = node } hash end
def to_h(table_name = nil, equality_only: false)
def to_h(table_name = nil, equality_only: false) equalities(predicates, equality_only).each_with_object({}) do |node, hash| next if table_name&.!= node.left.relation.name name = node.left.name.to_s value = extract_node_value(node.right) hash[name] = value end end
def wrap_sql_literal(node)
def wrap_sql_literal(node) if ::String === node node = Arel.sql(node) end Arel::Nodes::Grouping.new(node) end
def |(other)
def |(other) WhereClause.new(predicates | other.predicates) end