Class: Metasploit::ERD::Entity::Class

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Clusterable

#domain

Constructor Details

#initialize(klass) ⇒ Class

Returns a new instance of Class.

Parameters:

  • klass (Class<ActiveRecord::Base>)


23
24
25
# File 'lib/metasploit/erd/entity/class.rb', line 23

def initialize(klass)
  @klass = klass
end

Instance Attribute Details

#klassClass<ActiveRecord::Base> (readonly)

The class whose belongs_to associations should be followed to generate set of Classes on which it depends.

Returns:

  • (Class<ActiveRecord::Base>)


10
11
12
# File 'lib/metasploit/erd/entity/class.rb', line 10

def klass
  @klass
end

Instance Method Details

#class_setSet<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.

Parameters:

  • source (Class<ActiveRecord::Base>)

    an ActiveRecord::Base subclass.

Returns:

  • (Set<Class<ActiveRecord::Base>>)


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

#clusterMetasploit::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.

Examples:

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

Parameters:

  • options (Hash{Symbol => Object}) (defaults to: {})

    options controlling what to include from domain and how to render diagram. Defaults to Diagram::DEFAULT_OPTIONS.

Options Hash (options):

  • :basename (String)

    The basename to use for the :filename option. Only use only if not nil.

  • :diretory (String) — default: Dir.pwd

    The directory to use for the :filename options. Only used if :basename is not nil.

  • :basename (String) — default: "<klass.name.underscore>.erd"

    The basename to use for the :filename option.

  • :title (String) — default: "<klass.name> Namespace Entity-Relationship Diagram"

    Title for diagram.

  • :attributes (Array<Symbol>) — default: ATTRIBUTES

    attributes of each entity (table) to include in the diagram.

  • :filetype (String, Symbol) — default: FILETYPE

    the file type of the generated diagram. Supported formats depend on formats supported by graphviz installation.

  • :indirect (Boolean) — default: INDIRECT

    Whether to include indirect (has_many through:) relationships.

  • :inheritance (Boolean) — default: INHERITANCE

    Whether to include Single Table Inheritance (STI) subclass entities.

  • :notation (Symbol) — default: NOTATION

    The cardinality notation to be used. Refer to RailsERD documentation for availble notations.

  • :orientation (:horizontal, :vertical) — default: :horizontal

    The directory of the hierarchy of entities.

  • :polymorphism (Boolean) — default: POLYMORPHISM

    Whether to include abstract or polymorphic pseudo-entities.

  • :title (String)

    Title for diagram.

Returns:

  • (Metasploit::ERD:Diagram)


61
62
63
64
65
66
67
68
# 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