Skip to content

Commit

Permalink
Merge pull request #325 from voormedia/pr-304
Browse files Browse the repository at this point in the history
Rebase of #304 - Handle paper_trail's custom version classes.
  • Loading branch information
kerrizor committed May 12, 2019
2 parents cb5686e + b780bef commit 6fe72c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/rails_erd/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def check_association_validity(association)
association.check_validity!

if association.options[:polymorphic]
entity_name = association.class_name
entity_by_name(entity_name) or raise "polymorphic interface #{entity_name} does not exist"
check_polymorphic_association_validity(association)
else
entity_name = association.klass.name # Raises NameError if the associated class cannot be found.
entity_by_name(entity_name) or raise "model #{entity_name} exists, but is not included in domain"
Expand All @@ -150,6 +149,17 @@ def check_association_validity(association)
warn "Ignoring invalid association #{association_description(association)} (#{e.message})"
end

def check_polymorphic_association_validity(association)
entity_name = association.class_name
entity = entity_by_name(entity_name)

if entity || (entity && entity.generalized?)
return entity
else
raise("polymorphic interface #{entity_name} does not exist")
end
end

def association_description(association)
"#{association.name.inspect} on #{association.active_record}"
end
Expand Down
2 changes: 2 additions & 0 deletions rails-erd.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "ruby-graphviz", "~> 1.2"
s.add_runtime_dependency "choice", "~> 0.2.0"

s.add_development_dependency "pry"

s.files = `git ls-files -- {bin,lib,test}/* CHANGES.rdoc LICENSE Rakefile README.md`.split("\n")
s.test_files = `git ls-files -- test/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "rubygems"
require "bundler/setup"
require 'pry'

require "active_record"

Expand Down

0 comments on commit 6fe72c6

Please sign in to comment.