class Metasploit::ERD::Entity::Class
Entity for Entity-Relationship Diagram that wraps a `Class<ActiveRecord::Base>` to assist with finding its {#class_set directly related classes}
Attributes
Attributes
Public Class Methods
@param klass [Class<ActiveRecord::Base>]
# File lib/metasploit/erd/entity/class.rb, line 23 def initialize(klass) @klass = klass end
Public Instance Methods
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.
@param source [Class<ActiveRecord::Base>] an `ActiveRecord::Base` subclass. @return [Set<Class<ActiveRecord::Base>>]
# 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 seeded with {#klass}.
@return [Metasploit::ERD::Cluster]
# File lib/metasploit/erd/entity/class.rb, line 45 def cluster Metasploit::ERD::Cluster.new(klass) end
(see Metasploit::ERD::Clusterable#diagram
)
@example Generate ERD for a Class
in directory
klass = Klass entity = Metasploit::ERD::Entity::Class.new(klass) # will add default .png extension diagram = entity.diagram(directory: directory) diagram.create
@option options [String] :basename (“<klass.name.underscore>.erd”) The basename to use for the `:filename`
option.
@option options [String] :title (“<klass.name> Namespace Entity-Relationship Diagram”) Title for diagram.
Metasploit::ERD::Clusterable#diagram
# File lib/metasploit/erd/entity/class.rb, line 61 def diagram(options={}) super_options = { basename: "#{klass.name.underscore}.erd", title: "#{klass} Entity-Relationship Diagram" }.merge(options) super(super_options) end