yard-metasploit-erd 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWE2Y2MxNTI0YzViNTYyZjZmN2E0Y2M2YTU4OTU0MjBkYTY5ODI5Mg==
5
+ data.tar.gz: !binary |-
6
+ ZTIzNWQ5ZjgzNzU4ZjM4MzQ3NWY2MWQ4OWU5MzM4MzcxZjIwODk1Mw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ODdhNTRmYTIxNDcxNWMyMTliNDBlY2Q0OWJjNDE2MTQ3YTM3NmI4Mzc2YWU2
10
+ OWJiY2Y1MmE5OWRkN2MzYjMxNTgxZTFmYzZkZTM1Yzk0MTJlYjk4YzU4MjM4
11
+ YmI1ZmQ5NzYwMmRkMTE5NmViODcxYjBjNDNhMmI2N2U0NmNiMzY=
12
+ data.tar.gz: !binary |-
13
+ NjQ2YjhkNDVmMTFkNTRmYWY2OGRiNjI5ZjNlMmQ4OWU2OWRlZTkxMjM5YTIz
14
+ OGZhNTJkOTVhOTE0YzgxMmU1MTVhMjdjYjIxZTY4NDliNjgzOTBmNWI1MDNj
15
+ ZjhlZDQ0NTEyYjY0OGE2ZTEzZGZjMDExZDkwNjJlNzkyNTAxZDI=
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,28 @@
1
+ # bundler
2
+ .bundle
3
+
4
+ # Rubymine
5
+ .idea
6
+
7
+ # rvm files should not be checked in as multiple rubies are supported in the CI builds
8
+ .ruby-gemset
9
+ .ruby-version
10
+ .rvmrc
11
+
12
+ # YARD
13
+ .yardoc
14
+ /doc/*
15
+ !/doc/example
16
+
17
+ # simplecov
18
+ coverage
19
+
20
+ # @see http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
21
+ Gemfile.lock
22
+
23
+ # built gems
24
+ pkg
25
+ *.gem
26
+
27
+ # compiled ruby from Rubinius
28
+ *.rbc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.simplecov ADDED
@@ -0,0 +1,42 @@
1
+ # RM_INFO is set when using Rubymine. In Rubymine, starting SimpleCov is
2
+ # controlled by running with coverage, so don't explicitly start coverage (and
3
+ # therefore generate a report) when in Rubymine. This _will_ generate a report
4
+ # whenever `rake spec` is run.
5
+ unless ENV['RM_INFO']
6
+ SimpleCov.start
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ # ignore this file
11
+ add_filter '.simplecov'
12
+
13
+ # Rake tasks aren't tested with rspec
14
+ add_filter 'Rakefile'
15
+ add_filter 'lib/tasks'
16
+
17
+ #
18
+ # Changed Files in Git Group
19
+ # @see http://fredwu.me/post/35625566267/simplecov-test-coverage-for-changed-files-only
20
+ #
21
+
22
+ untracked = `git ls-files --exclude-standard --others`
23
+ unstaged = `git diff --name-only`
24
+ staged = `git diff --name-only --cached`
25
+ all = untracked + unstaged + staged
26
+ changed_filenames = all.split("\n")
27
+
28
+ add_group 'Changed' do |source_file|
29
+ changed_filenames.detect { |changed_filename|
30
+ source_file.filename.end_with?(changed_filename)
31
+ }
32
+ end
33
+
34
+ add_group 'Libraries', 'lib'
35
+
36
+ #
37
+ # Specs are reported on to ensure that all examples are being run and all
38
+ # lets, befores, afters, etc are being used.
39
+ #
40
+
41
+ add_group 'Specs', 'spec'
42
+ end
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0
5
+ - 2.1
6
+ - jruby
7
+ - rbx
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yard-metasploit-erd.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ # markdown formatting for yard
8
+ gem 'kramdown', platforms: :jruby
9
+ # markdown formatting for yard
10
+ gem 'redcarpet', platforms: :ruby
11
+ # documentation
12
+ # 0.8.7.4 has a bug where setters are not documented when @!attribute is used
13
+ gem 'yard', '< 0.8.7.4'
14
+ end
15
+
16
+ group :test do
17
+ # blank?
18
+ # restrict for compatibility with rest of metasploit ecosystem until it upgrades to Rails 4
19
+ gem 'activesupport', '>= 3.2', '< 4.0.0'
20
+ # Upload coverage reports to coveralls.io
21
+ gem 'coveralls', require: false
22
+ # code coverage of tests
23
+ gem 'simplecov', require: false
24
+ end
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ Copyright (c) 2014 Rapid7, Inc.
2
+
3
+ License: BSD-3-clause
4
+
5
+ Redistribution and use in source and binary forms, with or without modification,
6
+ are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of Rapid7 LLC nor the names of its contributors
16
+ may be used to endorse or promote products derived from this software
17
+ without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # YARD::Metasploit::ERD [![Build Status](https://travis-ci.org/rapid7/yard-metasploit-erd.svg?branch=feature/gem-skeleton)](https://travis-ci.org/rapid7/yard-metasploit-erd)[![Code Climate](https://codeclimate.com/github/rapid7/yard-metasploit-erd.png)](https://codeclimate.com/github/rapid7/yard-metasploit-erd)[![Coverage Status](https://coveralls.io/repos/rapid7/yard-metasploit-erd/badge.png)](https://coveralls.io/r/rapid7/yard-metasploit-erd)[![Dependency Status](https://gemnasium.com/rapid7/yard-metasploit-erd.png)](https://gemnasium.com/rapid7/yard-metasploit-erd)[![Gem Version](https://badge.fury.io/rb/yard-metasploit-erd.png)](http://badge.fury.io/rb/yard-metasploit-erd)
2
+
3
+ `yard-metasploit-erd` is a [YARD](yardoc.org) plugin that automatically inserts an "Entity-Relationship Diagram"
4
+ subsection containing a PNG Entity-Relationship Diagram for the entire schema (on the index page), for each Module that
5
+ contains `ActiveRecord::Base` subclasses and for each `ActiveRecord::Base` subclass.
6
+
7
+ For namespace Modules, the diagrams are restricted to the `ActiveRecord::Base` subclasses in that namespace and the
8
+ transitive closure of those classes `belongs_to` relationships.
9
+
10
+ ![Mdm::Module::Author ERD](doc/example/images/mdm/module/author.erd.png)
11
+
12
+ For `ActiveRecord::Base` subclasses the diagram is restricted to the transitive closure of its `belongs_to`
13
+ relationships.
14
+
15
+ ![Mdm::Module namespace ERD](doc/example/images/mdm/module.erd.png)
16
+
17
+ Using the `belongs_to` transitive closure means that all foreign keys are mapped to primary keys, so any diagram's
18
+ namespace or class could be extracted to another gem without leaving dangling foreign keys.
19
+
20
+ ## Versioning
21
+
22
+ `YARD::Metasploit::ERD` is versioned using [semantic versioning 2.0](http://semver.org/spec/v2.0.0.html). Each branch
23
+ should set `YARD::Metasploit::ERD::Version::PRERELEASE` to the branch name, while master should have no `PRERELEASE`
24
+ and the `PRERELEASE` section of `YARD::Metasploit::ERD::VERSION` does not exist.
25
+
26
+ ## Installation
27
+
28
+ Add this line to your application's `Gemfile`:
29
+
30
+ gem 'yard-metasploit-erd'
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install yard-metasploit-erd
39
+
40
+ ## Usage
41
+
42
+ Add this line to your application's `.yardopts`
43
+
44
+ --plugin yard-metasploit-erd
45
+
46
+ Ensure your `ActiveRecord::Base` subclasses are loaded when YARD runs by eager loading before the `yard:doc` task runs:
47
+
48
+ # lib/tasks/yard.rake
49
+ task 'yard:doc' => :eager_load
50
+
51
+ task eager_load: :environment do
52
+ Rails.application.eager_load!
53
+ end
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it ( https://github.com/[my-github-username]/yard-metasploit-erd/fork )
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+
5
+ load 'tasks/yard.rake'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
@@ -0,0 +1,32 @@
1
+ # @note All options not specific to any given rake task should go in the .yardopts file so they are available to both
2
+ # the below rake tasks and when invoking `yard` from the command line
3
+
4
+ if defined? YARD
5
+ namespace :yard do
6
+ YARD::Rake::YardocTask.new(:doc) do |t|
7
+ # --no-stats here as 'stats' task called after will print fuller stats
8
+ t.options = ['--no-stats']
9
+
10
+ t.after = Proc.new {
11
+ Rake::Task['yard:stats'].execute
12
+ }
13
+ end
14
+
15
+ task :doc
16
+
17
+ desc "Shows stats for YARD Documentation including listing undocumented modules, classes, constants, and methods"
18
+ task :stats do
19
+ stats = YARD::CLI::Stats.new
20
+ stats.run('--compact', '--list-undoc')
21
+ end
22
+ end
23
+
24
+ # @todo Figure out how to just clone description from yard:doc
25
+ desc "Generate YARD documentation"
26
+ # allow calling namespace to as a task that goes to default task for namespace
27
+ task :yard => ['yard:doc']
28
+
29
+ task :default => :yard
30
+ else
31
+ puts 'YARD not defined, so yard tasks cannot be setup.'
32
+ end
@@ -0,0 +1,33 @@
1
+ module YARD
2
+ module Metasploit
3
+ module ERD
4
+ # Holds components of {VERSION} as defined by {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0}.
5
+ module Version
6
+ # The major version number.
7
+ MAJOR = 0
8
+ # The minor version number, scoped to the {MAJOR} version number.
9
+ MINOR = 0
10
+ # The patch number, scoped to the {MINOR} version number.
11
+ PATCH = 2
12
+
13
+ # The full version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the {PRERELEASE} in the
14
+ # {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0} format.
15
+ #
16
+ # @return [String] '{MAJOR}.{MINOR}.{PATCH}' on master. '{MAJOR}.{MINOR}.{PATCH}-{PRERELEASE}' on any branch
17
+ # other than master.
18
+ def self.full
19
+ version = "#{MAJOR}.#{MINOR}.#{PATCH}"
20
+
21
+ if defined? PRERELEASE
22
+ version = "#{version}-#{PRERELEASE}"
23
+ end
24
+
25
+ version
26
+ end
27
+ end
28
+
29
+ # @see Version.full
30
+ VERSION = Version.full
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,43 @@
1
+ #
2
+ # Gems
3
+ #
4
+
5
+ require 'yard'
6
+
7
+ #
8
+ # Project
9
+ #
10
+
11
+ require 'yard/metasploit/erd/version'
12
+
13
+ # namespace inherited from `yard` gem itself
14
+ module YARD
15
+ # namespace to match primary gem, `metasploit-erd`, that is used by this yard plugin.
16
+ module Metasploit
17
+ # namespace to match primary gem, `metasploit-erd`, that is used by this yard plugin.
18
+ module ERD
19
+ # Registers {templates} in `YARD::Templates::Engine.templates_paths`.
20
+ #
21
+ # @return [void]
22
+ def self.register_template_path
23
+ YARD::Templates::Engine.register_template_path templates.to_path
24
+ end
25
+
26
+ # The root directory of the yard-metasploit-erd gem.
27
+ #
28
+ # @return [Pathname]
29
+ def self.root
30
+ @root ||= Pathname.new(__FILE__).parent.parent.parent.parent
31
+ end
32
+
33
+ # Path to the YARD templates for this YARD plugin.
34
+ #
35
+ # @return [Pathname]
36
+ def self.templates
37
+ root.join('templates')
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ YARD::Metasploit::ERD.register_template_path
@@ -0,0 +1,3 @@
1
+ # YARD does not follow gem naming conventions for its plugins: it treats '-' in names as literal instead of being
2
+ # directories.
3
+ require 'yard/metasploit/erd'
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ # require before 'metasploit/erd' so coverage is shown for files required by 'yard/metasploit/erd'
4
+ require 'simplecov'
5
+ require 'coveralls'
6
+
7
+ if ENV['TRAVIS'] == 'true'
8
+ # don't generate local report as it is inaccessible on travis-ci, which is why coveralls is being used.
9
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
10
+ else
11
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
12
+ # either generate the local report
13
+ SimpleCov::Formatter::HTMLFormatter
14
+ ]
15
+ end
16
+
17
+ require 'yard/metasploit/erd'
@@ -0,0 +1,143 @@
1
+ require 'spec_helper'
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+
5
+ describe YARD::Metasploit::ERD::Version do
6
+ context 'CONSTANTS' do
7
+ context 'MAJOR' do
8
+ subject(:major) do
9
+ described_class::MAJOR
10
+ end
11
+
12
+ it 'is 0 because the API is not locked yet' do
13
+ expect(major).to eq(0)
14
+ end
15
+ end
16
+
17
+ context 'MINOR' do
18
+ subject(:minor) do
19
+ described_class::MINOR
20
+ end
21
+
22
+ it { should be_a Integer }
23
+ end
24
+
25
+ context 'PATCH' do
26
+ subject(:patch) do
27
+ described_class::PATCH
28
+ end
29
+
30
+ it { should be_a Integer }
31
+ end
32
+
33
+ pull_request = ENV['TRAVIS_PULL_REQUEST']
34
+
35
+ # a pull request cannot check PRERELEASE because it will be tested in the target branch, but the source itself
36
+ # is from the source branch and so has the source branch PRERELEASE.
37
+ #
38
+ # PRERELEASE can only be set appropriately for a merge by merging to the target branch and then updating PRERELEASE
39
+ # on the target branch before committing and/or pushing to github and travis-ci.
40
+ if pull_request.nil? || pull_request == 'false'
41
+ context 'PREPRELEASE' do
42
+ subject(:prerelease) do
43
+ described_class::PRERELEASE
44
+ end
45
+
46
+ branch = ENV['TRAVIS_BRANCH']
47
+
48
+ if branch.blank?
49
+ branch = `git rev-parse --abbrev-ref HEAD`.strip
50
+ end
51
+
52
+ if branch == 'master'
53
+ it 'does not have a PRERELEASE' do
54
+ expect(defined? described_class::PRERELEASE).to be_nil
55
+ end
56
+ else
57
+ branch_regex = /\A(feature|staging)\/(?<prerelease>.*)\z/
58
+ match = branch.match(branch_regex)
59
+
60
+ if match
61
+ it 'matches the branch relative name' do
62
+ expect(prerelease).to eq(match[:prerelease])
63
+ end
64
+ else
65
+ tag_regex = /\Av(?<major>\d+).(?<minor>\d+).(?<patch>\d+)(-(?<prerelease>.*))?\z/
66
+ # travis-ci sets TRAVIS_BRANCH to the tag name for tag builds
67
+ match = branch.match(tag_regex)
68
+
69
+ if match
70
+ tag_prerelease = match[:prerelease]
71
+
72
+ if tag_prerelease
73
+ it 'matches the tag prerelease' do
74
+ expect(prerelease).to eq(tag_prerelease)
75
+ end
76
+ else
77
+ it 'does not have a PRERELEASE' do
78
+ expect(defined? described_class::PRERELEASE).to be_nil
79
+ end
80
+ end
81
+ else
82
+ it 'has a abbreviated reference that can be parsed for prerelease' do
83
+ fail "Do not know how to parse #{branch.inspect} for PRERELEASE"
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ context 'full' do
93
+ subject(:full) do
94
+ described_class.full
95
+ end
96
+
97
+ #
98
+ # lets
99
+ #
100
+
101
+ let(:major) do
102
+ 1
103
+ end
104
+
105
+ let(:minor) do
106
+ 2
107
+ end
108
+
109
+ let(:patch) do
110
+ 3
111
+ end
112
+
113
+ before(:each) do
114
+ stub_const("#{described_class}::MAJOR", major)
115
+ stub_const("#{described_class}::MINOR", minor)
116
+ stub_const("#{described_class}::PATCH", patch)
117
+ end
118
+
119
+ context 'with PRERELEASE' do
120
+ let(:prerelease) do
121
+ 'prerelease'
122
+ end
123
+
124
+ before(:each) do
125
+ stub_const("#{described_class}::PRERELEASE", prerelease)
126
+ end
127
+
128
+ it 'is <major>.<minor>.<patch>-<prerelease>' do
129
+ expect(full).to eq("#{major}.#{minor}.#{patch}-#{prerelease}")
130
+ end
131
+ end
132
+
133
+ context 'without PRERELEASE' do
134
+ before(:each) do
135
+ hide_const("#{described_class}::PRERELEASE")
136
+ end
137
+
138
+ it 'is <major>.<minor>.<patch>' do
139
+ expect(full).to eq("#{major}.#{minor}.#{patch}")
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe YARD::Metasploit::ERD do
4
+ context 'CONSTANTS' do
5
+ context 'VERSION' do
6
+ subject(:version) do
7
+ described_class::VERSION
8
+ end
9
+
10
+ it 'is YARD::Metasploit::ERD::Version.full' do
11
+ expect(version).to eq(YARD::Metasploit::ERD::Version.full)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ <h2>Entity-Relationship Diagram</h2>
2
+
3
+ <figure>
4
+ <img src="<%= url_for_file("images/#{object.title.underscore}.erd.png") %>" alt="<%= object.title %> Entity-Relationship Diagram">
5
+ <figcaption>
6
+ The cluster found by tracing <code>belongs_to</code> associations from <code><%= object.title %></code>
7
+ </figcaption>
8
+ </figure>
@@ -0,0 +1,25 @@
1
+ #
2
+ # Gems
3
+ #
4
+
5
+ require 'metasploit/erd'
6
+
7
+ def active_record?
8
+ inheritance_tree = object.inheritance_tree
9
+ inheritance_titles = inheritance_tree.map(&:title)
10
+
11
+ inheritance_titles.include? 'ActiveRecord::Base'
12
+ end
13
+
14
+ def entity
15
+ unless @entity
16
+ if active_record?
17
+ klass = object.title.constantize
18
+ @entity = ::Metasploit::ERD::Entity::Class.new(klass)
19
+ else
20
+ super
21
+ end
22
+ end
23
+
24
+ @entity
25
+ end
@@ -0,0 +1,8 @@
1
+ <h2>Entity-Relationship Diagram</h2>
2
+
3
+ <figure>
4
+ <img src="<%= url_for_file("images/_index.erd.png") %>" alt="Entity-Relationship Diagram">
5
+ <figcaption>
6
+ Full Entity-Relationship Diagram for this project.
7
+ </figcaption>
8
+ </figure>
@@ -0,0 +1,73 @@
1
+ #
2
+ # Gems
3
+ #
4
+
5
+ require 'metasploit/erd'
6
+ require 'rails_erd/domain'
7
+
8
+ def init
9
+ super
10
+
11
+ if object == '_index.html'
12
+ layout = sections[:layout]
13
+
14
+ unless layout
15
+ raise ArgumentError,
16
+ "Could not find layout subsection in root sections"
17
+ end
18
+
19
+ index = layout[:index]
20
+
21
+ unless index
22
+ raise ArgumentError,
23
+ "Could not find index subsection in layout section"
24
+ end
25
+
26
+ index.place(:entity_relationship_diagram).before(:listing)
27
+ end
28
+ end
29
+
30
+ #
31
+ # Generates a file to the output with the specified contents.
32
+ #
33
+ # @example saving a custom html file to the documenation root
34
+ #
35
+ # asset('my_custom.html','<html><body>Custom File</body></html>')
36
+ #
37
+ # @param [String] path relative to the document output where the file will be
38
+ # created.
39
+ # @param [String] content the contents that are saved to the file.
40
+ def asset(path, content)
41
+ if options.serializer
42
+ log.capture("Generating asset #{path}") do
43
+ options.serializer.serialize(path, content)
44
+ end
45
+ end
46
+ end
47
+
48
+ def entity_relationship_diagram
49
+ generate_entity_relationship_diagram
50
+ erb(:entity_relationship_diagram)
51
+ end
52
+
53
+ def generate_entity_relationship_diagram
54
+ domain = RailsERD::Domain.new(
55
+ ActiveRecord::Base.descendants,
56
+ # No entities should be missing because all desendents are in domain.
57
+ warn: true
58
+ )
59
+
60
+ Dir.mktmpdir { |directory|
61
+ filename = File.join(directory, '_index.erd')
62
+ diagram = ::Metasploit::ERD::Diagram.new(
63
+ domain,
64
+ filename: filename,
65
+ title: 'Entity-Relationship Diagram'
66
+ )
67
+ temporary_path = diagram.create
68
+
69
+ content = File.read(temporary_path)
70
+ asset_path = File.join('images', "_index.erd.#{diagram.send(:filetype)}")
71
+ asset(asset_path, content)
72
+ }
73
+ end
@@ -0,0 +1,8 @@
1
+ <h2>Entity-Relationship Diagram</h2>
2
+
3
+ <figure>
4
+ <img src="<%= url_for_file("images/#{object.title.underscore}.erd.png") %>" alt="<%= object.title %> Entity-Relationship Diagram">
5
+ <figcaption>
6
+ The cluster found by tracing <code>belongs_to</code> associations from <code>ActiveRecord::Base</code> descendants under the <code><%= object.title %></code> namespace.
7
+ </figcaption>
8
+ </figure>
@@ -0,0 +1,60 @@
1
+ #
2
+ # Standard Library
3
+ #
4
+
5
+ require 'tempfile'
6
+
7
+ #
8
+ # Gems
9
+ #
10
+
11
+ require 'metasploit/erd'
12
+
13
+ def init
14
+ super
15
+ sections.place(:entity_relationship_diagram).before(:children)
16
+ end
17
+
18
+ def entity_relationship_diagram
19
+ unless erd_empty?
20
+ generate_entity_relationship_diagram
21
+ erb(:entity_relationship_diagram)
22
+ end
23
+ end
24
+
25
+ def erd_empty?
26
+ entity.cluster.class_set.empty?
27
+ end
28
+
29
+ def entity
30
+ @entity ||= ::Metasploit::ERD::Entity::Namespace.new(object.title)
31
+ end
32
+
33
+ #
34
+ # Generates a file to the output with the specified contents.
35
+ #
36
+ # @example saving a custom html file to the documenation root
37
+ #
38
+ # asset('my_custom.html','<html><body>Custom File</body></html>')
39
+ #
40
+ # @param [String] path relative to the document output where the file will be
41
+ # created.
42
+ # @param [String] content the contents that are saved to the file.
43
+ def asset(path, content)
44
+ if options.serializer
45
+ log.capture("Generating asset #{path}") do
46
+ options.serializer.serialize(path, content)
47
+ end
48
+ end
49
+ end
50
+
51
+ def generate_entity_relationship_diagram
52
+ Dir.mktmpdir { |directory|
53
+ diagram = entity.diagram(directory: directory)
54
+ temporary_path = diagram.create
55
+
56
+ content = File.read(temporary_path)
57
+ asset_path = File.join('images', "#{object.title.underscore}.erd.#{diagram.send(:filetype)}")
58
+ asset(asset_path, content)
59
+ }
60
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yard/metasploit/erd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'yard-metasploit-erd'
8
+ spec.version = YARD::Metasploit::ERD::VERSION
9
+ spec.authors = ['Luke Imhoff']
10
+ spec.email = ['luke_imhoff@rapid7.com']
11
+ spec.summary = 'YARD plugin that add Metasploit::ERDs to namespaces and classes'
12
+ spec.description = "YARD plugin that uses metasploit-erd to add Entity-Relationship Diagrams to each namespace " \
13
+ "Module and ActiveRecord::Base subclass's documentation."
14
+ spec.homepage = 'https://github.com/rapid7/yard-metasploit-erd'
15
+ spec.license = 'BSD-3-clause'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.5'
23
+ spec.add_development_dependency 'rake', '~> 10.3'
24
+ spec.add_development_dependency 'rspec', '~> 2.14'
25
+
26
+ # Generates namespace Module and Class<ActiveRecord::Base> specific ERDs for use in templates
27
+ spec.add_runtime_dependency 'metasploit-erd', '0.0.1'
28
+ # RailsERD::Domain is used directly to generate the _index.html ERD.
29
+ spec.add_runtime_dependency 'rails-erd'
30
+ # documentation
31
+ # 0.8.7.4 has a bug where setters are not documented when @!attribute is used
32
+ spec.add_runtime_dependency 'yard', '<= 0.8.7.4'
33
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-metasploit-erd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Luke Imhoff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: metasploit-erd
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails-erd
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - <=
88
+ - !ruby/object:Gem::Version
89
+ version: 0.8.7.4
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - <=
95
+ - !ruby/object:Gem::Version
96
+ version: 0.8.7.4
97
+ description: YARD plugin that uses metasploit-erd to add Entity-Relationship Diagrams
98
+ to each namespace Module and ActiveRecord::Base subclass's documentation.
99
+ email:
100
+ - luke_imhoff@rapid7.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .coveralls.yml
106
+ - .gitignore
107
+ - .rspec
108
+ - .simplecov
109
+ - .travis.yml
110
+ - .yardopts
111
+ - Gemfile
112
+ - LICENSE
113
+ - README.md
114
+ - Rakefile
115
+ - doc/example/images/mdm/module.erd.png
116
+ - doc/example/images/mdm/module/author.erd.png
117
+ - lib/tasks/yard.rake
118
+ - lib/yard-metasploit-erd.rb
119
+ - lib/yard/metasploit/erd.rb
120
+ - lib/yard/metasploit/erd/version.rb
121
+ - spec/spec_helper.rb
122
+ - spec/yard/metasploit/erd/version_spec.rb
123
+ - spec/yard/metasploit/erd_spec.rb
124
+ - templates/default/class/html/entity_relationship_diagram.erb
125
+ - templates/default/class/html/setup.rb
126
+ - templates/default/layout/html/entity_relationship_diagram.erb
127
+ - templates/default/layout/html/setup.rb
128
+ - templates/default/module/html/entity_relationship_diagram.erb
129
+ - templates/default/module/html/setup.rb
130
+ - yard-metasploit-erd.gemspec
131
+ homepage: https://github.com/rapid7/yard-metasploit-erd
132
+ licenses:
133
+ - BSD-3-clause
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.2.2
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: YARD plugin that add Metasploit::ERDs to namespaces and classes
155
+ test_files:
156
+ - spec/spec_helper.rb
157
+ - spec/yard/metasploit/erd/version_spec.rb
158
+ - spec/yard/metasploit/erd_spec.rb
159
+ has_rdoc: