lib/kasket/visitor.rb in kasket-4.10.4 vs lib/kasket/visitor.rb in kasket-4.11.0

- old
+ new

@@ -47,11 +47,11 @@ query end def visit_Arel_Nodes_SelectCore(node, *_) return :unsupported if node.groups.any? - return :unsupported if ActiveRecord::VERSION::MAJOR < 5 ? node.having : node.havings.present? + return :unsupported if node.havings.present? return :unsupported if node.set_quantifier return :unsupported if !node.source || node.source.empty? return :unsupported if node.projections.empty? select = node.projections[0] @@ -63,23 +63,27 @@ projection_names = node.projections.map { |p| p.name if p.respond_to?(:name) }.compact return unless (column_names - projection_names).empty? end + # un-optimize AR 6.1 by adding a redundant And node to hit visitor below + if ActiveRecord::VERSION::STRING.start_with? "6.1" + if node.wheres.size == 1 + n = node.wheres[0] + node.wheres[0] = Arel::Nodes::And.new([n]) unless n.is_a?(Arel::Nodes::And) + end + end + parts = [visit(node.source)] parts += node.wheres.map {|where| visit(where) } parts.include?(:unsupported) ? :unsupported : parts end def visit_Arel_Nodes_Limit(node, *_) - if ActiveRecord::VERSION::MAJOR < 5 - { limit: node.value.to_i } - else - { limit: visit(node.value).to_i } - end + { limit: visit(node.value).to_i } end def visit_Arel_Nodes_JoinSource(node, *_) return :unsupported if !node.left || node.right.any? return :unsupported unless node.left.is_a?(Arel::Table) @@ -104,10 +108,12 @@ return :unsupported if left != :id [left, visit(node.right)] end + alias_method :visit_Arel_Nodes_HomogeneousIn, :visit_Arel_Nodes_In + def visit_Arel_Nodes_Equality(node, *_) right = case node.right when false then 0 # This should probably be removed when Rails 3.2 is not supported anymore when nil then nil @@ -132,18 +138,14 @@ node.to_s end end def visit_Arel_Nodes_BindParam(node, *_) - if ActiveRecord::VERSION::MAJOR < 5 - visit(@binds.shift[1]) + if ActiveRecord::VERSION::STRING < '5.2' + visit(@binds.shift) else - if ActiveRecord::VERSION::STRING < '5.2' - visit(@binds.shift) - else - visit(node.value.value) unless node.value.value.nil? - end + visit(node.value.value) unless node.value.value.nil? end end def visit_Array(node, *_) node.map {|value| visit(value) } @@ -153,9 +155,18 @@ def visit_Arel_Nodes_Casted(node, *_) case node.val when nil then nil when String then node.val else quoted(node.val) + end + end + else # R52: val -> value + def visit_Arel_Nodes_Casted(node, *_) + v = node.value + case v + when nil then nil + when String then v + else quoted(v) end end end def visit_TrueClass(_node)