class RuboCop::Cop::Style::MigrationComments
Constants
- COMMON_DB_FIELDS
- MSG
Public Instance Methods
on_def(node)
click to toggle source
# File lib/rubocop/cop/style/migration_comments.rb, line 12 def on_def(node) body = node.children[2] if body.type == :send process_block_child_node(body) else body.each_child_node do |ancestor| process_block_child_node(ancestor) end end end
Private Instance Methods
process_block_child_node(ancestor)
click to toggle source
# File lib/rubocop/cop/style/migration_comments.rb, line 25 def process_block_child_node(ancestor) if ancestor.type == :block return unless ancestor.send_node.source.start_with? "create_table" ancestor.body.each_child_node do |innder_ancestor| process_entries_inside_create_table(innder_ancestor) end else first_child = ancestor.children[1] return unless first_child == :add_column field_name = ancestor.children[3].source return if COMMON_DB_FIELDS.include? field_name last_child = ancestor.children[-1] return if last_child.type == :hash && last_child.each_key.any? {|key| [":comment", "comment"].include? key.source} add_offense(ancestor, :expression) end end
process_entries_inside_create_table(ancestor)
click to toggle source
# File lib/rubocop/cop/style/migration_comments.rb, line 45 def process_entries_inside_create_table(ancestor) field_name = ancestor.children[2].source return if COMMON_DB_FIELDS.include? field_name last_child = ancestor.children[-1] return if last_child.type == :hash && last_child.each_key.any? {|key| [":comment", "comment"].include? key.source} add_offense(ancestor, :expression) end