Class: RuboCop::Cop::DevDoc::Migration::DateColumnNaming
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::DevDoc::Migration::DateColumnNaming
- Defined in:
- lib/rubocop/cop/dev_doc/migration/date_column_naming.rb
Overview
Date columns should end with ‘_on`; datetime columns should end with `_at`.
## Rationale Use the suffix ‘_on` for `date` columns and `_at` for `datetime` columns. This convention makes the column type immediately clear from the name, without having to look at the schema. For example:
service_subscription.expiring_on # date
service_subscription.expired_at # datetime
Constant Summary collapse
- DATE_MSG =
'Date column `%<name>s` should end with `_on` (e.g. `%<name>s_on`).'.freeze
- DATETIME_MSG =
'Datetime column `%<name>s` should end with `_at` (e.g. `%<name>s_at`).'.freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rubocop/cop/dev_doc/migration/date_column_naming.rb', line 29 def on_send(node) if node.method?(:add_column) check_add_column(node) elsif %i[date datetime timestamptz].include?(node.method_name) check_column_definition(node) end end |