Class: DBDiagram::Domain::Entity
- Inherits:
-
Object
- Object
- DBDiagram::Domain::Entity
- Extended by:
- Inspectable
- Defined in:
- lib/db_diagram/domain/entity.rb
Overview
Entities represent your Active Record models. Entities may be connected to other entities.
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
The domain in which this entity resides.
-
#model ⇒ Object
readonly
The Active Record model that this entity corresponds to.
-
#name ⇒ Object
readonly
The name of this entity.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#abstract? ⇒ Boolean
Returns
true
if this entity does not correspond directly with a database table (if and only if the entity is specialized or generalized). -
#attributes ⇒ Object
Returns an array of attributes for this entity.
-
#generalized? ⇒ Boolean
Returns
true
if this entity is a generalization, which does not correspond with a database table. -
#initialize(domain, model) ⇒ Entity
constructor
A new instance of Entity.
- #model_name ⇒ Object
- #namespace ⇒ Object
-
#relationships ⇒ Object
Returns an array of all relationships that this entity has with other entities in the domain model.
- #to_s ⇒ Object
Methods included from Inspectable
Constructor Details
#initialize(domain, model) ⇒ Entity
Returns a new instance of Entity.
31 32 33 34 |
# File 'lib/db_diagram/domain/entity.rb', line 31 def initialize(domain, model) # @private :nodoc: @domain, @model = domain, model @name = !!model.abstract_class? ? model.name : model.table_name end |
Instance Attribute Details
#domain ⇒ Object (readonly)
The domain in which this entity resides.
22 23 24 |
# File 'lib/db_diagram/domain/entity.rb', line 22 def domain @domain end |
#model ⇒ Object (readonly)
The Active Record model that this entity corresponds to.
25 26 27 |
# File 'lib/db_diagram/domain/entity.rb', line 25 def model @model end |
#name ⇒ Object (readonly)
The name of this entity. Equal to the class name of the corresponding model (for concrete entities) or given name (for abstract entities).
29 30 31 |
# File 'lib/db_diagram/domain/entity.rb', line 29 def name @name end |
Class Method Details
.from_models(domain, models) ⇒ Object
7 8 9 |
# File 'lib/db_diagram/domain/entity.rb', line 7 def from_models(domain, models) # @private :nodoc: concrete_from_models(domain, models).sort end |
Instance Method Details
#<=>(other) ⇒ Object
76 77 78 |
# File 'lib/db_diagram/domain/entity.rb', line 76 def <=>(other) # @private :nodoc: self.name <=> other.name end |
#abstract? ⇒ Boolean
Returns true
if this entity does not correspond directly with a database table (if and only if the entity is specialized or generalized).
60 61 62 |
# File 'lib/db_diagram/domain/entity.rb', line 60 def abstract? generalized? end |
#attributes ⇒ Object
Returns an array of attributes for this entity.
37 38 39 |
# File 'lib/db_diagram/domain/entity.rb', line 37 def attributes @attributes ||= generalized? ? [] : Attribute.from_model(domain, model) end |
#generalized? ⇒ Boolean
Returns true
if this entity is a generalization, which does not correspond with a database table. Generalized entities are either models that are defined as abstract_class
or they are constructed from polymorphic interfaces. Any has_one
or has_many
association that defines a polymorphic interface with :as => :name
will lead to a generalized entity to be created.
53 54 55 |
# File 'lib/db_diagram/domain/entity.rb', line 53 def generalized? !!model.abstract_class? end |
#model_name ⇒ Object
68 69 70 |
# File 'lib/db_diagram/domain/entity.rb', line 68 def model_name model.name end |
#namespace ⇒ Object
64 65 66 |
# File 'lib/db_diagram/domain/entity.rb', line 64 def namespace $1 if name.match(/(.*)::.*/) end |
#relationships ⇒ Object
Returns an array of all relationships that this entity has with other entities in the domain model.
43 44 45 |
# File 'lib/db_diagram/domain/entity.rb', line 43 def relationships domain.relationships_by_entity_name(name) end |
#to_s ⇒ Object
72 73 74 |
# File 'lib/db_diagram/domain/entity.rb', line 72 def to_s # @private :nodoc: name end |