Class: RailsERD::Domain
- Inherits:
-
Object
- Object
- RailsERD::Domain
- Extended by:
- Inspectable
- Defined in:
- lib/rails_erd/domain.rb,
lib/rails_erd/domain/entity.rb,
lib/rails_erd/domain/attribute.rb,
lib/rails_erd/domain/relationship.rb,
lib/rails_erd/domain/specialization.rb,
lib/rails_erd/domain/relationship/cardinality.rb
Overview
The domain describes your Rails domain model. This class is the starting point to get information about your models.
Options
The following options are available:
- warn
-
When set to
false
, no warnings are printed to the command line while processing the domain model. Defaults totrue
.
Defined Under Namespace
Classes: Attribute, Entity, NullGeneralized, NullSpecialization, Relationship, Specialization
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
The options that are used to generate this domain model.
Class Method Summary collapse
-
.foreign_key_method_name ⇒ Object
Returns the method name to retrieve the foreign key from an association reflection object.
-
.generate(options = {}) ⇒ Object
Generates a domain model object based on all loaded subclasses of
ActiveRecord::Base
.
Instance Method Summary collapse
-
#entities ⇒ Object
Returns all entities of your domain model.
-
#entity_by_name(name) ⇒ Object
Returns a specific entity object for the given Active Record model.
-
#initialize(models = [], options = {}) ⇒ Domain
constructor
Create a new domain model object based on the given array of models.
-
#name ⇒ Object
Returns the domain model name, which is the name of your Rails application or
nil
outside of Rails. -
#relationships ⇒ Object
Returns all relationships in your domain model.
-
#relationships_by_entity_name(name) ⇒ Object
Returns an array of relationships for the given Active Record model.
-
#specializations ⇒ Object
Returns all specializations in your domain model.
- #specializations_by_entity_name(name) ⇒ Object
- #warn(message) ⇒ Object
Methods included from Inspectable
Constructor Details
#initialize(models = [], options = {}) ⇒ Domain
Create a new domain model object based on the given array of models. The given models are assumed to be subclasses of ActiveRecord::Base
.
45 46 47 |
# File 'lib/rails_erd/domain.rb', line 45 def initialize(models = [], = {}) @source_models, @options = models, RailsERD..merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
The options that are used to generate this domain model.
41 42 43 |
# File 'lib/rails_erd/domain.rb', line 41 def @options end |
Class Method Details
.foreign_key_method_name ⇒ Object
Returns the method name to retrieve the foreign key from an association reflection object.
32 33 34 |
# File 'lib/rails_erd/domain.rb', line 32 def foreign_key_method_name # @private :nodoc: @foreign_key_method_name ||= ActiveRecord::Reflection::AssociationReflection.method_defined?(:foreign_key) ? :foreign_key : :primary_key_name end |
.generate(options = {}) ⇒ Object
Generates a domain model object based on all loaded subclasses of ActiveRecord::Base
. Make sure your models are loaded before calling this method.
The options
hash allows you to override the default options. For a list of available options, see RailsERD.
26 27 28 |
# File 'lib/rails_erd/domain.rb', line 26 def generate( = {}) new ActiveRecord::Base.descendants, end |
Instance Method Details
#entities ⇒ Object
Returns all entities of your domain model.
62 63 64 |
# File 'lib/rails_erd/domain.rb', line 62 def entities @entities ||= Entity.from_models(self, models) end |
#entity_by_name(name) ⇒ Object
Returns a specific entity object for the given Active Record model.
77 78 79 |
# File 'lib/rails_erd/domain.rb', line 77 def entity_by_name(name) # @private :nodoc: entity_mapping[name] end |
#name ⇒ Object
Returns the domain model name, which is the name of your Rails application or nil
outside of Rails.
51 52 53 54 55 56 57 58 59 |
# File 'lib/rails_erd/domain.rb', line 51 def name return unless defined?(Rails) && Rails.application if Rails.application.class.respond_to?(:module_parent) Rails.application.class.module_parent.name else Rails.application.class.parent.name end end |
#relationships ⇒ Object
Returns all relationships in your domain model.
67 68 69 |
# File 'lib/rails_erd/domain.rb', line 67 def relationships @relationships ||= Relationship.from_associations(self, associations) end |
#relationships_by_entity_name(name) ⇒ Object
Returns an array of relationships for the given Active Record model.
82 83 84 |
# File 'lib/rails_erd/domain.rb', line 82 def relationships_by_entity_name(name) # @private :nodoc: relationships_mapping[name] or [] end |
#specializations ⇒ Object
Returns all specializations in your domain model.
72 73 74 |
# File 'lib/rails_erd/domain.rb', line 72 def specializations @specializations ||= Specialization.from_models(self, models) end |
#specializations_by_entity_name(name) ⇒ Object
86 87 88 |
# File 'lib/rails_erd/domain.rb', line 86 def specializations_by_entity_name(name) specializations_mapping[name] or [] end |
#warn(message) ⇒ Object
90 91 92 |
# File 'lib/rails_erd/domain.rb', line 90 def warn() # @private :nodoc: puts "Warning: #{}" if .warn end |