From db53d58b777cfd3b344ee1e141921cd0374a9ec7 Mon Sep 17 00:00:00 2001 From: Syed Faraaz Ahmad <113512303+faraaz-deepsource@users.noreply.github.com> Date: Tue, 1 Aug 2023 04:35:35 +0530 Subject: [PATCH] Error handling (#46) * ci: Update .deepsource.toml * fix: handle more edge cases --------- Co-authored-by: deepsource-totalanarchy[bot] <107136100+deepsource-totalanarchy[bot]@users.noreply.github.com> --- lib/trains/scanner.rb | 5 +++-- lib/trains/visitor/model.rb | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/trains/scanner.rb b/lib/trains/scanner.rb index dda1bd9..a8e7093 100644 --- a/lib/trains/scanner.rb +++ b/lib/trains/scanner.rb @@ -66,9 +66,10 @@ def get_routes def parse_schema result_hash = {} - schema_file = [File.join(@dir, 'db', 'schema.rb')] - models_results = parse_util(schema_file, Visitor::Schema) + schema_file = File.join(@dir, 'db', 'schema.rb') + return result_hash unless File.exist? schema_file + models_results = parse_util([schema_file], Visitor::Schema) models_results .select { |result| result.error.nil? } .map(&:data) diff --git a/lib/trains/visitor/model.rb b/lib/trains/visitor/model.rb index c3fef8d..3d6af0d 100644 --- a/lib/trains/visitor/model.rb +++ b/lib/trains/visitor/model.rb @@ -9,7 +9,11 @@ class Model < Base belongs_to has_one has_and_belongs_to_many - ] + ].freeze + MODEL_PARENT_CLASSES = %w[ + ApplicationRecord + ActiveRecord::Base + ].freeze attr_reader :result # skipcq: RB-LI1087 @@ -19,7 +23,7 @@ def initialize def on_class(node) return unless node.parent_class - return unless node.parent_class.source == 'ApplicationRecord' + return unless MODEL_PARENT_CLASSES.include? node.parent_class.source @model_class = node.identifier.source node.each_descendant(:send) { |send_node| parse_model(send_node) }