Skip to content

Commit

Permalink
Error handling (#46)
Browse files Browse the repository at this point in the history
* ci: Update .deepsource.toml

* fix: handle more edge cases

---------

Co-authored-by: deepsource-totalanarchy[bot] <107136100+deepsource-totalanarchy[bot]@users.noreply.github.com>
  • Loading branch information
1 parent dc575b7 commit db53d58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/trains/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions lib/trains/visitor/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }
Expand Down

0 comments on commit db53d58

Please sign in to comment.