Class: Metasploit::ERD::Entity::Class
- Inherits:
-
Object
- Object
- Metasploit::ERD::Entity::Class
- Includes:
- Clusterable
- Defined in:
- lib/metasploit/erd/entity/class.rb
Overview
Entity for Entity-Relationship Diagram that wraps a Class<ActiveRecord::Base>
to assist with finding its
directly related classes
Instance Attribute Summary collapse
-
#klass ⇒ Class<ActiveRecord::Base>
readonly
The class whose
belongs_to
associations should be followed to generate set of Classes on which it depends.
Instance Method Summary collapse
-
#class_set ⇒ Set<Class<ActiveRecord::Base>>
Returns all classes to which the #klass has a
belongs_to
association. -
#cluster ⇒ Metasploit::ERD::Cluster
Cluster seeded with #klass.
-
#diagram(options = {}) ⇒ Metasploit::ERD:Diagram
Diagram using Clusterable#domain.
-
#initialize(klass) ⇒ Class
constructor
A new instance of Class.
Methods included from Clusterable
Constructor Details
#initialize(klass) ⇒ Class
Returns a new instance of Class.
23 24 25 |
# File 'lib/metasploit/erd/entity/class.rb', line 23 def initialize(klass) @klass = klass end |
Instance Attribute Details
#klass ⇒ Class<ActiveRecord::Base> (readonly)
The class whose belongs_to
associations should be followed to generate
set of Classes on which it depends.
10 11 12 |
# File 'lib/metasploit/erd/entity/class.rb', line 10 def klass @klass end |
Instance Method Details
#class_set ⇒ Set<Class<ActiveRecord::Base>>
Returns all classes to which the #klass has a belongs_to
association. Only belongs_to
associations are traced
because they have foreign keys and without the belongs_to associations the foreign keys would have no primary keys
to which to point.
33 34 35 36 37 38 39 40 |
# File 'lib/metasploit/erd/entity/class.rb', line 33 def class_set reflections = klass.reflect_on_all_associations(:belongs_to) reflections.each_with_object(Set.new) { |reflection, set| relationship = Metasploit::ERD::Relationship.new(reflection) set.merge(relationship.class_set) } end |
#cluster ⇒ Metasploit::ERD::Cluster
Cluster seeded with #klass.
45 46 47 |
# File 'lib/metasploit/erd/entity/class.rb', line 45 def cluster Metasploit::ERD::Cluster.new(klass) end |
#diagram(options = {}) ⇒ Metasploit::ERD:Diagram
Diagram using Clusterable#domain.
61 62 63 64 65 66 67 68 |
# File 'lib/metasploit/erd/entity/class.rb', line 61 def diagram(={}) = { basename: "#{klass.name.underscore}.erd", title: "#{klass} Entity-Relationship Diagram" }.merge() super() end |