@klass = node.class_name.to_s end add_callback :start_command do |node| if node.message.to_s == 'belongs_to' association_name = node.arguments.all.first.to_s add_association(@klass, association_name) end end
if node.message.to_s == 'add_index' table_name = node.arguments.all.first.to_s index_column = node.arguments.all[1].to_object @index_columns[table_name] << index_column end end
@index_columns[klass.table_name].include?(association_name.column_name) add_error "always add db index (#{klass.table_name} => #{association_name.column_name})", table_node.file, table_node.line_number end end end
def query_nodes(node) # iterate all child nodes, # check if child node matches node_type end def match?(node) @node_type.to_sym == NodeQuery.adapter.get_node_type(node) end end end selector = NodeQueryParser.new.parse(nql) selector.query_nodes(node) # matching_nodes
node_type @attribute = attribute end def query_nodes(node) # iterate all child nodes, # check if child node matches node_type and attribute end def match?(node) @node_type.to_sym == NodeQuery.adapter.get_node_type(node) && (!@attribute || @attribute.match?(node)) end end class Attribute def initialize(key:, value:, operator: '=') @key = key @value = value @operator = operator end def match?(node) @value.match?(NodeQuery::Helper.get_target_node(node, @key), node, @operator) end end end selector = NodeQueryParser.new.parse(nql) selector.query_nodes(node) # matching_nodes
Post < ApplicationRecord 4 end 5 class Post < ApplicationRecord end class Post < ActiveRecord::Base 1 end 2 3 4 5 replace node, :parent_class, with: 'ApplicationRecord'
Post < ApplicationRecord 4 end 5 class Post < ApplicationRecord end class Post < ActiveRecord::Base 1 end 2 3 4 5 replace node, :parent_class, with: 'ApplicationRecord' [{ start: 'class Post < '.length, end: 'class Post < ActiveRecord::Base'.length, new_code: 'ApplicationRecord' }]
2 3 4 end 5 6 class TestMeme < Minitest::Test 7 def setup 8 super 9 do_something 10 end 11 end 12 def setup super do_something end class TestMeme < Minitest::Test 1 def setup 2 do_something 3 end 4 end 5 6 class TestMeme < Minitest::Test 7 8 9 10 11 end 12 prepend node, 'super'
2 3 4 end 5 6 class TestMeme < Minitest::Test 7 def teardown 8 clean_something 9 super 10 end 11 end 12 def teardown clean_something super end class TestMeme < Minitest::Test 1 def teardown 2 clean_something 3 end 4 end 5 6 class TestMeme < Minitest::Test 7 8 9 10 11 end 12 append node, 'super'