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

klass[R]

Attributes

Public Class Methods

new(klass) click to toggle source

@param klass [Class<ActiveRecord::Base>]

# File lib/metasploit/erd/entity/class.rb, line 23
def initialize(klass)
  @klass = klass
end

Public Instance Methods

class_set() click to toggle source

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() click to toggle source

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
diagram(options={}) click to toggle source

(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.

Calls superclass method 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