Class: Gitlab::Styles::Rubocop::Cop::Migration::Datetime
- Inherits:
-
RuboCop::Cop::Cop
- Object
- RuboCop::Cop::Cop
- Gitlab::Styles::Rubocop::Cop::Migration::Datetime
- Includes:
- MigrationHelpers
- Defined in:
- lib/gitlab/styles/rubocop/cop/migration/datetime.rb
Overview
Cop that checks if datetime data type is added with timezone information.
Constant Summary collapse
- MSG =
'Do not use the `datetime` data type, use `datetime_with_timezone` instead'.freeze
Instance Method Summary collapse
- #method_name(node) ⇒ Object
-
#on_def(node) ⇒ Object
Check methods in table creation.
-
#on_send(node) ⇒ Object
Check methods.
Methods included from MigrationHelpers
Instance Method Details
#method_name(node) ⇒ Object
32 33 34 |
# File 'lib/gitlab/styles/rubocop/cop/migration/datetime.rb', line 32 def method_name(node) node.children[1] end |
#on_def(node) ⇒ Object
Check methods in table creation.
15 16 17 18 19 20 21 |
# File 'lib/gitlab/styles/rubocop/cop/migration/datetime.rb', line 15 def on_def(node) return unless in_migration?(node) node.each_descendant(:send) do |send_node| add_offense(send_node, :selector) if method_name(send_node) == :datetime end end |
#on_send(node) ⇒ Object
Check methods.
24 25 26 27 28 29 30 |
# File 'lib/gitlab/styles/rubocop/cop/migration/datetime.rb', line 24 def on_send(node) return unless in_migration?(node) node.each_descendant do |descendant| add_offense(node, :expression) if descendant.type == :sym && descendant.children.last == :datetime end end |