Class: RailsERD::Domain::Specialization

Inherits:
Object
  • Object
show all
Extended by:
Inspectable
Defined in:
lib/rails_erd/domain/specialization.rb

Overview

Describes the specialization of an entity. Specialized entities correspond to inheritance or polymorphism. In Rails, specialization is referred to as single table inheritance, while generalization is referred to as polymorphism or abstract classes.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Inspectable

inspection_attributes

Constructor Details

#initialize(domain, generalized, specialized) ⇒ Specialization

Returns a new instance of Specialization.



58
59
60
61
62
# File 'lib/rails_erd/domain/specialization.rb', line 58

def initialize(domain, generalized, specialized) # @private :nodoc:
  @domain = domain
  @generalized = generalized || NullGeneralized.new
  @specialized = specialized || NullSpecialization.new
end

Instance Attribute Details

#domainObject (readonly)

The domain in which this specialization is defined.



50
51
52
# File 'lib/rails_erd/domain/specialization.rb', line 50

def domain
  @domain
end

#generalizedObject (readonly)

The source entity.



53
54
55
# File 'lib/rails_erd/domain/specialization.rb', line 53

def generalized
  @generalized
end

#specializedObject (readonly)

The destination entity.



56
57
58
# File 'lib/rails_erd/domain/specialization.rb', line 56

def specialized
  @specialized
end

Class Method Details

.from_models(domain, models) ⇒ Object



9
10
11
12
13
14
# File 'lib/rails_erd/domain/specialization.rb', line 9

def from_models(domain, models) # @private :nodoc:
  models = polymorphic_from_models(domain, models) +
    inheritance_from_models(domain, models) +
    abstract_from_models(domain, models)
  models.sort
end

Instance Method Details

#<=>(other) ⇒ Object



74
75
76
# File 'lib/rails_erd/domain/specialization.rb', line 74

def <=>(other) # @private :nodoc:
  (generalized.name <=> other.generalized.name).nonzero? or (specialized.name <=> other.specialized.name)
end

#generalization?Boolean Also known as: polymorphic?

Returns:

  • (Boolean)


64
65
66
# File 'lib/rails_erd/domain/specialization.rb', line 64

def generalization?
  generalized.generalized?
end

#specialization?Boolean Also known as: inheritance?

Returns:

  • (Boolean)


69
70
71
# File 'lib/rails_erd/domain/specialization.rb', line 69

def specialization?
  !generalization?
end