Skip to content

Commit

Permalink
Allow variable to find_xquery
Browse files Browse the repository at this point in the history
  • Loading branch information
sue445 committed Oct 20, 2021
1 parent 6571282 commit f3191f8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/rubocop/cop/isucon/mixin/mysql2_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ module Mysql2Methods
extend NodePattern::Macros

def_node_search :find_xquery, <<~PATTERN
(send (send nil? _) {:xquery | :query} (${str dstr} $...) ...)
(send (send nil? _) {:xquery | :query} (${str dstr lvar ivar cvar} $...) ...)
PATTERN

# @param node [RuboCop::AST::Node]
# @yieldparam type [Symbol] Node type. one of `:str`, `:dstr`
# @yieldparam root_gda [RuboCop::Isucon::GDA::Client]
# @yieldparam root_gda [RuboCop::Isucon::GDA::Client,nil]
#
# @note If arguments of `db.xquery` isn't string, `root_gda` is `nil`
def with_xquery(node)
find_xquery(node) do |type, params|
sql = xquery_param(type: type, params: params)

root_gda = RuboCop::Isucon::GDA::Client.new(sql)
root_gda = sql ? RuboCop::Isucon::GDA::Client.new(sql) : nil

yield type, root_gda
end
Expand Down

0 comments on commit f3191f8

Please sign in to comment.