Class: RuboCop::Cop::Sequel::JSONColumn

Inherits:
Base
  • Object
show all
Includes:
Helpers::Migration
Defined in:
lib/rubocop/cop/sequel/json_column.rb

Overview

JSONColumn looks for non-JSONB columns.

Constant Summary collapse

MSG =
'Use JSONB rather than JSON or hstore'
RESTRICT_ON_SEND =
%i[add_column].freeze

Instance Method Summary collapse

Methods included from Helpers::Migration

#within_sequel_migration?

Instance Method Details

#on_block(node) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/cop/sequel/json_column.rb', line 32

def on_block(node)
  return unless node.send_node.method_name == :create_table
  return unless within_sequel_migration?(node)

  node.each_node(:send) do |method|
    next unless column_method?(method) || column_type?(method)

    add_offense(method.loc.selector, message: MSG)
  end
end

#on_send(node) ⇒ Object



25
26
27
28
29
30
# File 'lib/rubocop/cop/sequel/json_column.rb', line 25

def on_send(node)
  return unless json_or_hstore?(node)
  return unless within_sequel_migration?(node)

  add_offense(node.loc.selector, message: MSG)
end