rails_model_visualizer 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +78 -7
- data/docs/wireframes/general.png +0 -0
- data/lib/rails_model_visualizer/templates.rb +0 -1
- data/lib/rails_model_visualizer/version.rb +1 -1
- data/rails_model_visualizer.gemspec +4 -12
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86130c5792ba0a41e7ae9ccf94857dc3808102ac
|
4
|
+
data.tar.gz: 138fda69b18e854e1c8e333de1cd67ae9f9fe487
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8468876e5ede05321477e942dbedb0580ca49247a5aa2542332933d180cbf00e405ea8596133b66b8d16f765b725ced7c4332b5a882b9c9e2320633acfbafc05
|
7
|
+
data.tar.gz: 8769f6e23ca4160df45118c4ce09f5af56a89e484f4796e093a0a5dc2ec8bf88a09f94812d67878e3cfd23f22f1b0aa6c9eff870516fbb7a2d6ec56a9b77e53a
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# RailsModelVisualizer
|
2
2
|
|
3
|
-
|
3
|
+
RailsModelVisualizer is a ruby gem which improves documentation of rails
|
4
|
+
apps by generating an html output visualizing rails models.
|
4
5
|
|
5
|
-
|
6
|
+

|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -22,18 +23,88 @@ Or install it yourself as:
|
|
22
23
|
|
23
24
|
## Usage
|
24
25
|
|
25
|
-
|
26
|
+
In order to use RailsModelVisualizer, execute the following line in the rails console.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
RMVisualizer.print_models
|
30
|
+
```
|
31
|
+
|
32
|
+
This will generate and launch an html file visualizing rails models. Typically, all rails models will inherit from `ActiveRecord::Base`, thus one outer box representing the superclass will be displayed. In case another superclass is also present, more than one outer box will also be displayed.
|
33
|
+
|
34
|
+
Within each outer box, there will be inner boxes representing rails models. In the current version of the gem, three main type of information is displayed.
|
35
|
+
|
36
|
+
- SQL Columns
|
37
|
+
In this section, column names of the model's table is listed. Hovering on a column name shows the data type (integer, timestamp, etc.).
|
38
|
+
|
39
|
+
- Methods
|
40
|
+
Both public and private methods of the model are listed here. Hovering on a method name shows the source code for that method.
|
41
|
+
|
42
|
+
- Associations
|
43
|
+
`ActiveRecord` associations are listed in this section. If an option for the association is defined (for example `class_name`), it is shown while hovering on the association name.
|
26
44
|
|
27
45
|
## Development
|
28
46
|
|
29
|
-
|
47
|
+
The gem is build on Ruby. `RMVisualizer` class imports model information
|
48
|
+
from Rails and creates `Model` instances.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
def self.import_models
|
52
|
+
if Rails.application
|
53
|
+
Rails.application.eager_load!
|
54
|
+
return ActiveRecord::Base.descendants.map do |rails_model|
|
55
|
+
Model.new(rails_model)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
return []
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
30
62
|
|
31
|
-
|
63
|
+
Superclass, SQL columns, methods and associations are imported from rails, as well. For example, the instance methods are imported as follows.
|
32
64
|
|
33
|
-
|
65
|
+
```ruby
|
66
|
+
def get_methods(type)
|
67
|
+
filename = "#{@name.underscore}.rb"
|
68
|
+
result = {};
|
69
|
+
|
70
|
+
@rails_model.new.method(type).call(false).each do |pm|
|
71
|
+
source_file = source(@rails_model, pm)
|
72
|
+
if source_file[0].include?(filename)
|
73
|
+
result[pm] = source_code(source_file, pm)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
result
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
where the type is either `:private_methods` or `:public_methods`. The argument `false` in method call filters out methods not defined by the user.
|
82
|
+
|
83
|
+
Method source code is read from the sourcefile as follows.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
def source_code(source_file, method)
|
87
|
+
path, start_line = source_file
|
88
|
+
source_code = []
|
89
|
+
line_to_read = start_line - 1
|
90
|
+
file = File.readlines(path)
|
34
91
|
|
35
|
-
|
92
|
+
while true
|
93
|
+
source_code.push(indent(file[line_to_read]))
|
94
|
+
break if file[line_to_read] == " end\n"
|
95
|
+
|
96
|
+
line_to_read += 1
|
97
|
+
end
|
98
|
+
|
99
|
+
source_code.join("<br>")
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
This approach as long as the indentation is correct.
|
104
|
+
|
105
|
+
## Contributing
|
36
106
|
|
107
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/HCoban/rails_model_visualizer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
37
108
|
|
38
109
|
## License
|
39
110
|
|
Binary file
|
@@ -10,20 +10,12 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ["Halil Coban"]
|
11
11
|
spec.email = ["halil.coban@gmail.com"]
|
12
12
|
|
13
|
-
spec.summary = %q{
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
spec.summary = %q{RailsModelVisualizer is a ruby gem which
|
14
|
+
improves documentation of rails apps by generating an html output
|
15
|
+
visualizing rails models.}
|
16
|
+
spec.homepage = "https://github.com/HCoban/rails_model_visualizer"
|
17
17
|
spec.license = "MIT"
|
18
18
|
|
19
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
20
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
21
|
-
# if spec.respond_to?(:metadata)
|
22
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
23
|
-
# else
|
24
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
25
|
-
# end
|
26
|
-
|
27
19
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
20
|
spec.bindir = "exe"
|
29
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_model_visualizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Halil Coban
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,13 +104,14 @@ files:
|
|
104
104
|
- bin/console
|
105
105
|
- bin/setup
|
106
106
|
- docs/readme.md
|
107
|
+
- docs/wireframes/general.png
|
107
108
|
- docs/wireframes/wireframe.png
|
108
109
|
- lib/rails_model_visualizer.rb
|
109
110
|
- lib/rails_model_visualizer/model.rb
|
110
111
|
- lib/rails_model_visualizer/templates.rb
|
111
112
|
- lib/rails_model_visualizer/version.rb
|
112
113
|
- rails_model_visualizer.gemspec
|
113
|
-
homepage:
|
114
|
+
homepage: https://github.com/HCoban/rails_model_visualizer
|
114
115
|
licenses:
|
115
116
|
- MIT
|
116
117
|
metadata: {}
|
@@ -133,5 +134,6 @@ rubyforge_project:
|
|
133
134
|
rubygems_version: 2.5.1
|
134
135
|
signing_key:
|
135
136
|
specification_version: 4
|
136
|
-
summary:
|
137
|
+
summary: RailsModelVisualizer is a ruby gem which improves documentation of rails
|
138
|
+
apps by generating an html output visualizing rails models.
|
137
139
|
test_files: []
|