summaryrefslogtreecommitdiff
path: root/rubocop/cop/activerecord_serialize.rb
diff options
context:
space:
mode:
Diffstat (limited to 'rubocop/cop/activerecord_serialize.rb')
-rw-r--r--rubocop/cop/activerecord_serialize.rb16
1 files changed, 5 insertions, 11 deletions
diff --git a/rubocop/cop/activerecord_serialize.rb b/rubocop/cop/activerecord_serialize.rb
index bfa0cff9a67..9bdcc3b4c34 100644
--- a/rubocop/cop/activerecord_serialize.rb
+++ b/rubocop/cop/activerecord_serialize.rb
@@ -1,24 +1,18 @@
+require_relative '../model_helpers'
+
module RuboCop
module Cop
# Cop that prevents the use of `serialize` in ActiveRecord models.
class ActiverecordSerialize < RuboCop::Cop::Cop
+ include ModelHelpers
+
MSG = 'Do not store serialized data in the database, use separate columns and/or tables instead'.freeze
def on_send(node)
- return unless in_models?(node)
+ return unless in_model?(node)
add_offense(node, :selector) if node.children[1] == :serialize
end
-
- def models_path
- File.join(Dir.pwd, 'app', 'models')
- end
-
- def in_models?(node)
- path = node.location.expression.source_buffer.name
-
- path.start_with?(models_path)
- end
end
end
end