Sha256: af9db5ed39986114813412da961c84098ea778ecf3ee8b6a6fc3d38122f480b9
Contents?: true
Size: 1.84 KB
Versions: 1
Compression:
Stored size: 1.84 KB
Contents
module RailsERD class Domain # Describes the specialization of an entity. Specialized entites correspond # to inheritance. In Rails, specialization is referred to as single table # inheritance. class Specialization class << self def from_models(domain, models) # @private :nodoc: (inheritance_from_models(domain, models) + polymorphic_from_models(domain, models)).sort end private def polymorphic_from_models(domain, models) models.collect(&:reflect_on_all_associations).flatten.collect { |association| [association.options[:as].to_s.classify, association.active_record.name] if association.options[:as] }.compact.uniq.collect { |names| new(domain, domain.entity_by_name(names.first), domain.entity_by_name(names.last)) } end def inheritance_from_models(domain, models) models.reject(&:descends_from_active_record?).collect { |model| new(domain, domain.entity_by_name(model.base_class.name), domain.entity_by_name(model.name)) } end end extend Inspectable inspection_attributes :generalized, :specialized # The domain in which this specialization is defined. attr_reader :domain # The source entity. attr_reader :generalized # The destination entity. attr_reader :specialized def initialize(domain, generalized, specialized) # @private :nodoc: @domain, @generalized, @specialized = domain, generalized, specialized end def inheritance? !polymorphic? end def polymorphic? generalized.generalized? end def <=>(other) # @private :nodoc: (generalized.name <=> other.generalized.name).nonzero? or (specialized.name <=> other.specialized.name) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails-erd-1.0.0 | lib/rails_erd/domain/specialization.rb |