documented 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5026a405923100cfe8ea3f484fe324b3588a3481369fd954b7d5645537227672
4
+ data.tar.gz: b9d86b71d1a7dfc1018edc79922a54fd2013245d95c17eb9d902d5dd8160f100
5
+ SHA512:
6
+ metadata.gz: 55480519881df342fcbff4d0b7ea3b7aef9a6ca96805c3eb18283faf3f43b3e83d8e3df00219310e75293123fd801993848630a7c446626407812b745ae6c896
7
+ data.tar.gz: 994c10ccf460e023790c8caaa4198f5bf63f06b41b6ebebefc604b1752af27f1d4610d3f62297f08f0e124f62d7a1786af8ad16e2e9e8e5e31d1bb86db269df4
data/lib/accessor.rb ADDED
@@ -0,0 +1,31 @@
1
+ ################################################################################
2
+ # Access variables via one object to avoid polluting the caller's scope.
3
+ #
4
+ # @pattern Singleton
5
+ ################################################################################
6
+
7
+ module Documented
8
+ class Accessor
9
+ attr_accessor :initialized
10
+ attr_accessor :error
11
+
12
+ attr_accessor :config
13
+ attr_accessor :renderer
14
+
15
+ attr_accessor :package_path
16
+ attr_accessor :project_path
17
+ attr_accessor :output_path
18
+
19
+ def initialize()
20
+ @initialized = false
21
+ @error = nil
22
+
23
+ @config = nil
24
+ @renderer = nil
25
+
26
+ @package_path = nil
27
+ @project_path = nil
28
+ @output_path = nil
29
+ end
30
+ end
31
+ end
data/lib/config.rb ADDED
@@ -0,0 +1,46 @@
1
+ module Documented
2
+ class Config
3
+ attr_accessor :blocklist
4
+ attr_accessor :duplicates
5
+ attr_accessor :project_path
6
+ attr_accessor :output_directory
7
+
8
+ def initialize()
9
+ @blocklist = [
10
+ '#<Class:Bundler',
11
+ '#<Class:#<Class',
12
+ '#<Class:0x0000',
13
+ '#<Class:Cucumber',
14
+ '#<Class:JSON>',
15
+ '#<Class:Net::',
16
+ '#<Class:Time',
17
+ '#<Class:URI::Generic>',
18
+ '#<Class:URI>',
19
+ '#<Module',
20
+ '#<refinement',
21
+ 'BasicSocket',
22
+ 'Bundler',
23
+ 'Cucumber',
24
+ 'Datadog',
25
+ 'Float',
26
+ 'Helpers',
27
+ 'Integer',
28
+ 'Kernel',
29
+ 'Net::',
30
+ 'NilClass',
31
+ 'Set',
32
+ 'Thread',
33
+ 'Timeout::Request',
34
+ 'TracePoint',
35
+ 'URI::',
36
+ 'URI::Generic',
37
+ ]
38
+
39
+ # An absolute path to the project root directory. Defaults to current execution path.
40
+ @project_path = Dir.pwd
41
+
42
+ # Name of output directory.
43
+ @output_directory = "documented"
44
+ end
45
+ end
46
+ end
data/lib/documented.rb ADDED
@@ -0,0 +1,82 @@
1
+ require 'set'
2
+ require 'erb'
3
+
4
+ require_relative 'accessor'
5
+ require_relative 'config'
6
+ require_relative 'renderer'
7
+
8
+ module Documented
9
+ def documented
10
+ events = []
11
+ calls = ['Start']
12
+
13
+ trace = TracePoint.new(:call, :return) do |tp|
14
+ # file = File.open("#{__dir__}/../../doc/diagrams/input.mmd")
15
+ # file.write("sequenceDiagram\n")
16
+
17
+ # file.close
18
+ caller = calls.last.to_s
19
+ callee = tp.defined_class.to_s
20
+ event = tp.event
21
+
22
+ unless blocklist.any? { |e| callee.to_s.start_with? e }
23
+ unless calls.last == callee
24
+ if event == :return
25
+ calls.pop
26
+ elsif calls.last != callee
27
+ calls << callee
28
+ end
29
+ end
30
+
31
+ unless callee == caller
32
+ caller = caller.gsub('::','.')
33
+ callee = callee.gsub('::','.')
34
+ p "#{caller}->>#{callee}: #{tp.method_id}"
35
+ end
36
+ end
37
+ end
38
+
39
+ trace.enable
40
+
41
+ yield
42
+
43
+ trace.disable
44
+
45
+ ap events
46
+ end
47
+
48
+ def self.configure
49
+ documented_setup_class()
50
+
51
+ yield(@@documented.config)
52
+ end
53
+
54
+ def self.included(base)
55
+ documented_setup_class()
56
+ end
57
+
58
+ private
59
+
60
+ ##
61
+ # Setup class.
62
+ #
63
+ # @paths
64
+ # - package_path [String] Absolute path to the library itself.
65
+ # - project_path [String] Absolute path to the project root.
66
+ # - output_path [String] Absolute path to the documented directory.
67
+ ##
68
+ def self.documented_setup_class()
69
+ @@documented = Accessor.new()
70
+ @@documented.config = Config.new()
71
+
72
+ # Setup paths.
73
+ @@documented.package_path = File.dirname(File.realpath(__FILE__))
74
+ @@documented.project_path = @@documented.config.project_path
75
+ @@documented.output_path = File.join(@@documented.project_path, @@documented.config.output_directory)
76
+ unless Dir.exist? @@documented.output_path
77
+ Dir.mkdir(@@documented.output_path)
78
+ end
79
+
80
+ @@documented.renderer = Renderer.new(@@documented.package_path, @@documented.output_path)
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ # Documented
2
+
3
+ As you test the application documentation will be added to `/documented`.
@@ -0,0 +1,2 @@
1
+ .gitignore
2
+ README.md
data/lib/renderer.rb ADDED
@@ -0,0 +1,27 @@
1
+ module Documented
2
+ class Renderer
3
+ def initialize(package_path, output_path)
4
+ @package_path = package_path
5
+ @output_path = output_path
6
+ end
7
+
8
+ # Place files in output path.
9
+ def render()
10
+ filenames = [
11
+ "README.md",
12
+ ]
13
+
14
+ filenames.each do |filename|
15
+ file = File.read(File.join(@package_path, "output", filename))
16
+ File.open(File.join(@output_path, filename), 'w+') do |f|
17
+ f.write file
18
+ end
19
+ end
20
+
21
+ file = File.read(File.join(@package_path, "output", "gitignore.txt"))
22
+ File.open(File.join(@output_path, ".gitignore"), 'w+') do |f|
23
+ f.write file
24
+ end
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: documented
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Maedi Prichard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Documentation that's completely automated.
28
+ email: maediprichard@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/accessor.rb
34
+ - lib/config.rb
35
+ - lib/documented.rb
36
+ - lib/output/README.md
37
+ - lib/output/gitignore.txt
38
+ - lib/renderer.rb
39
+ homepage: https://github.com/greensync/documented
40
+ licenses:
41
+ - MPL-2.0
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.4.10
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Automated documentation.
62
+ test_files: []