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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74b719c6e52da8ef01549c4eeebffcaaa202924e
4
- data.tar.gz: 3fe284d7fe93d667b3cb5d35a541a91c5047e638
3
+ metadata.gz: 86130c5792ba0a41e7ae9ccf94857dc3808102ac
4
+ data.tar.gz: 138fda69b18e854e1c8e333de1cd67ae9f9fe487
5
5
  SHA512:
6
- metadata.gz: 9a66c64b68359f34ec4a9d6aa854e41d6a6e38a4a804670b4c5bc5ef042268b65a95feddbfebf1b12db18ae54a0b09f541916eff156da0d0316846b59c5b23ee
7
- data.tar.gz: d2888fd5740789e4022289509ebe768d1dabbbbcae8401a1b7b748083060ac53206cf41a41f0446b9bbf5500d1311911ec0e550a6f76a58857ca2f502a76735f
6
+ metadata.gz: 8468876e5ede05321477e942dbedb0580ca49247a5aa2542332933d180cbf00e405ea8596133b66b8d16f765b725ced7c4332b5a882b9c9e2320633acfbafc05
7
+ data.tar.gz: 8769f6e23ca4160df45118c4ce09f5af56a89e484f4796e093a0a5dc2ec8bf88a09f94812d67878e3cfd23f22f1b0aa6c9eff870516fbb7a2d6ec56a9b77e53a
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # RailsModelVisualizer
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_model_visualizer`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ RailsModelVisualizer is a ruby gem which improves documentation of rails
4
+ apps by generating an html output visualizing rails models.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ ![main_image](/docs/wireframes/general.png)
6
7
 
7
8
  ## Installation
8
9
 
@@ -22,18 +23,88 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
25
- TODO: Write usage instructions here
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- ## Contributing
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
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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.
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
@@ -67,7 +67,6 @@ class RMVisualizer
67
67
  color: black;
68
68
  z-index: 1;
69
69
  left:150px;
70
- padding: 5px;
71
70
  border-radius: 3px;
72
71
  text-align: left;
73
72
  }
@@ -1,3 +1,3 @@
1
1
  class RMVisualizer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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{RMVisualizer is a ruby gem that generates a diagram
14
- summarizing rails apps.}
15
- # spec.description = %q{TODO: Write a longer description or delete this line.}
16
- # spec.homepage = "TODO: Put your gem's website or public repo URL here."
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.0
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-23 00:00:00.000000000 Z
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: RMVisualizer is a ruby gem that generates a diagram summarizing rails apps.
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: []