Class: RailsERD::Domain::Specialization
- Inherits:
-
Object
- Object
- RailsERD::Domain::Specialization
- 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
-
#domain ⇒ Object
readonly
The domain in which this specialization is defined.
-
#generalized ⇒ Object
readonly
The source entity.
-
#specialized ⇒ Object
readonly
The destination entity.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #generalization? ⇒ Boolean (also: #polymorphic?)
-
#initialize(domain, generalized, specialized) ⇒ Specialization
constructor
A new instance of Specialization.
- #specialization? ⇒ Boolean (also: #inheritance?)
Methods included from Inspectable
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
#domain ⇒ Object (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 |
#generalized ⇒ Object (readonly)
The source entity.
53 54 55 |
# File 'lib/rails_erd/domain/specialization.rb', line 53 def generalized @generalized end |
#specialized ⇒ Object (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?
64 65 66 |
# File 'lib/rails_erd/domain/specialization.rb', line 64 def generalization? generalized.generalized? end |
#specialization? ⇒ Boolean Also known as: inheritance?
69 70 71 |
# File 'lib/rails_erd/domain/specialization.rb', line 69 def specialization? !generalization? end |