class DBDiagram::Domain::Entity

Entities represent your Active Record models. Entities may be connected to other entities.

Attributes

domain[R]

The domain in which this entity resides.

model[R]

The Active Record model that this entity corresponds to.

name[R]

The name of this entity. Equal to the class name of the corresponding model (for concrete entities) or given name (for abstract entities).

Private Class Methods

concrete_from_models(domain, models) click to toggle source
# File lib/db_diagram/domain/entity.rb, line 13
def concrete_from_models(domain, models)
  models.collect { |model| new(domain, model) }
end

Public Instance Methods

abstract?() click to toggle source

Returns true if this entity does not correspond directly with a database table (if and only if the entity is specialized or generalized).

# File lib/db_diagram/domain/entity.rb, line 60
def abstract?
  generalized?
end
attributes() click to toggle source

Returns an array of attributes for this entity.

# File lib/db_diagram/domain/entity.rb, line 37
def attributes
  @attributes ||= generalized? ? [] : Attribute.from_model(domain, model)
end
generalized?() click to toggle source

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.

# File lib/db_diagram/domain/entity.rb, line 53
def generalized?
  !!model.abstract_class?
end
model_name() click to toggle source
# File lib/db_diagram/domain/entity.rb, line 68
def model_name
  model.name
end
namespace() click to toggle source
# File lib/db_diagram/domain/entity.rb, line 64
def namespace
  $1 if name.match(/(.*)::.*/)
end
relationships() click to toggle source

Returns an array of all relationships that this entity has with other entities in the domain model.

# File lib/db_diagram/domain/entity.rb, line 43
def relationships
  domain.relationships_by_entity_name(name)
end