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

Inherits:
Object
  • Object
show all
Includes:
Clusterable
Defined in:
lib/metasploit/erd/entity/namespace.rb

Overview

Entity for a namespace with a given name.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Clusterable

#domain

Constructor Details

#initialize(namespace_name) ⇒ Namespace

Returns a new instance of Namespace.

Parameters:

  • namespace_name (String)


21
22
23
# File 'lib/metasploit/erd/entity/namespace.rb', line 21

def initialize(namespace_name)
  @namespace_name = namespace_name
end

Instance Attribute Details

#namespace_nameString (readonly)

The Module#name of a namespace module for a collection of Class<ActiveRecord::Base>

Returns:

  • (String)


9
10
11
# File 'lib/metasploit/erd/entity/namespace.rb', line 9

def namespace_name
  @namespace_name
end

Instance Method Details

#classesArray<Class<ActiveRecord::Base>

Note:

Caller must load all ActiveRecord::Base descendants that should be in the search domain.

The entities in the namespace with namespace_name.

Parameters:

  • namespace_name (String)

    The Module#name of the Class or Module that is the namespace for a collection of ActiveRecord::Base descendants.

Returns:

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

    Array



32
33
34
35
36
37
38
# File 'lib/metasploit/erd/entity/namespace.rb', line 32

def classes
  ActiveRecord::Base.descendants.select { |klass|
    klass.module_parents.any? { |parent|
      parent.name == namespace_name
    }
  }
end

#clusterMetasploit::ERD::Cluster

Cluster seeded with all #classes in this namespace.



43
44
45
# File 'lib/metasploit/erd/entity/namespace.rb', line 43

def cluster
  Metasploit::ERD::Cluster.new(*classes)
end

#diagram(options = {}) ⇒ Metasploit::ERD:Diagram

Diagram using Clusterable#domain.

Examples:

Generate ERD for namespace in directory

entity = Metasploit::ERD::Entity::Namespace.new('Nested::Namespace')
# 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: "<namespace_name.underscore>.erd"

    The basename to use for the :filename option.

  • :title (String) — default: "<namespace_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)


58
59
60
61
62
63
64
65
# File 'lib/metasploit/erd/entity/namespace.rb', line 58

def diagram(options={})
  super_options = {
      basename: "#{namespace_name.underscore}.erd",
      title: "#{namespace_name} Namespace Entity-Relationship Diagram"
  }.merge(options)

  super(super_options)
end