Sha256: 6da0074b9f3c810fe48abca63e7dcc24df43035e1ac98c779a4b6a38180465bc
Contents?: true
Size: 1.2 KB
Versions: 5
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Sequel # JSONColumn looks for non-JSONB columns. class JSONColumn < Base include Helpers::Migration MSG = 'Use JSONB rather than JSON or hstore' RESTRICT_ON_SEND = %i[add_column].freeze def_node_matcher :json_or_hstore?, <<-MATCHER (send _ :add_column ... (sym {:json :hstore})) MATCHER def_node_matcher :column_type?, <<-MATCHER (send _ {:json :hstore} ...) MATCHER def_node_matcher :column_method?, <<-MATCHER (send _ :column ... (sym {:json :hstore})) MATCHER def on_send(node) return unless json_or_hstore?(node) return unless within_sequel_migration?(node) add_offense(node.loc.selector, message: MSG) end 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 end end end end
Version data entries
5 entries across 5 versions & 1 rubygems