Class: RuboCop::Cop::Code0::ZeroTrack::Migration::CreateTableWithTimestamps

Inherits:
Base
  • Object
show all
Includes:
RuboCop::Code0::ZeroTrack::FileHelpers
Defined in:
lib/rubocop/cop/code0/zero_track/migration/create_table_with_timestamps.rb

Constant Summary collapse

MSG =
'Add timestamps when creating a new table.'
RESTRICT_ON_SEND =
%i[create_table].freeze

Instance Method Summary collapse

Methods included from RuboCop::Code0::ZeroTrack::FileHelpers

#basename, #dirname, #filepath, #in_migration?

Instance Method Details

#on_send(node) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rubocop/cop/code0/zero_track/migration/create_table_with_timestamps.rb', line 43

def on_send(node)
  return unless in_migration?(node)
  return unless node.command?(:create_table)

  parent = node.parent

  if create_table_with_block?(parent)
    add_offense(parent) if parent.body.nil? || !time_columns_included?(parent.body)
  elsif create_table_with_timestamps_proc?(node)
    # nothing to do
  else
    add_offense(node)
  end
end