rubrowser 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/readme.md CHANGED
@@ -6,9 +6,9 @@ a visualizer for ruby code (rails or otherwise), it analyze your code and extrac
6
6
 
7
7
  this project is so small that the visualization looks like so
8
8
 
9
- ![rubrowser visualization](http://i.imgur.com/O2tbOJZ.png)
9
+ ![rubrowser visualization](http://i.imgur.com/HwLfJx2.png)
10
10
 
11
- the idea is that the project opens every `.rb` file and parse it with `parser` gem then list all modules and classes definitions, and all constants that are listed inside this module/class and link them together, there are couple things you need to keep in mind:
11
+ the idea is that the project opens every `.rb` file and parse it with `parser` gem then list all modules and classes definitions, and all constants that are listed inside this module/class and link them together.
12
12
 
13
13
  Here are some output examples
14
14
 
@@ -18,9 +18,10 @@ Here are some output examples
18
18
  | actioncable-5.0.0/lib | ![acioncable](http://i.imgur.com/Q0Xqjsz.png) |
19
19
  | railties-5.0.0/lib | ![railties](http://i.imgur.com/31g10a1.png) |
20
20
 
21
- * if your file doesn't have a valid ruby syntax it won't be parsed and will cause the gem to stop
21
+ there are couple things you need to keep in mind:
22
+
23
+ * if your file doesn't have a valid ruby syntax it won't be parsed and will print warning.
22
24
  * if you reference a class that is not defined in your project it won't be in the graph, we only display the graph of classes/modules you defined
23
- * the server analyze your code once upon the script starts if you changed your code you'll have to restart rubrowser
24
25
  * it statically analyze the code so meta programming is out of question in here
25
26
  * rails associations are meta programming so forget it :smile:
26
27
 
@@ -35,7 +36,7 @@ gem install rubrowser
35
36
 
36
37
 
37
38
  ```
38
- Usage: bin/rubrowser [options] [file] ...
39
+ Usage: rubrowser [options] [file] ...
39
40
  -p, --port=PORT Specify port number for server, default = 9000
40
41
  -v, --version Print Rubrowser version
41
42
  -h, --help Prints this help
@@ -57,7 +58,7 @@ it'll analyze the current directory and open port 9000, so you can access the gr
57
58
 
58
59
  ## Tests?
59
60
 
60
- what test? :D
61
+ What tests? :smile:
61
62
 
62
63
  ## Why?
63
64
 
data/views/index.erb CHANGED
@@ -4,13 +4,17 @@
4
4
  <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
5
5
  <title>Rubrowser</title>
6
6
  <link href='/css/application.css' media='all' rel='stylesheet'>
7
- <script src='/javascript/d3.js' type='text/javascript'></script>
8
- <script src='/javascript/jquery.js' type='text/javascript'></script>
9
- <script src='/javascript/application.js' type='text/javascript'></script>
10
7
  </head>
11
8
  <body>
12
9
  <div class='dependency_graph'>
13
- <svg data-constants="<%=h data.constants.to_json%>" data-occurences="<%=h data.occurences.to_json%>"></svg>
10
+ <svg></svg>
11
+ <div class="loading">
12
+ Parsing files...
13
+ </div>
14
14
  </div>
15
+ <script src='/javascript/lodash.js' type='text/javascript'></script>
16
+ <script src='/javascript/d3.js' type='text/javascript'></script>
17
+ <script src='/javascript/jquery.js' type='text/javascript'></script>
18
+ <script src='/javascript/application.js' type='text/javascript'></script>
15
19
  </body>
16
20
  </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubrowser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emad Elsaid
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-27 00:00:00.000000000 Z
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -39,21 +39,27 @@ extensions: []
39
39
  extra_rdoc_files: []
40
40
  files:
41
41
  - ".gitignore"
42
+ - ".rubocop.yml"
42
43
  - Gemfile
43
44
  - Gemfile.lock
45
+ - MIT-LICENSE
44
46
  - bin/rubrowser
45
- - lib/d3.rb
46
47
  - lib/data.rb
48
+ - lib/formatter/json.rb
49
+ - lib/parser/definition/base.rb
50
+ - lib/parser/definition/class.rb
51
+ - lib/parser/definition/module.rb
47
52
  - lib/parser/directory.rb
48
53
  - lib/parser/factory.rb
49
54
  - lib/parser/file.rb
55
+ - lib/parser/relation/base.rb
50
56
  - lib/rubrowser.rb
51
57
  - lib/server.rb
52
- - lib/tree.rb
53
58
  - public/css/application.css
54
59
  - public/javascript/application.js
55
60
  - public/javascript/d3.js
56
61
  - public/javascript/jquery.js
62
+ - public/javascript/lodash.js
57
63
  - readme.md
58
64
  - rubrowser.gemspec
59
65
  - views/index.erb
data/lib/d3.rb DELETED
@@ -1,33 +0,0 @@
1
- module Rubrowser
2
- class D3
3
- def initialize(node)
4
- @node = node
5
- end
6
-
7
- def constants
8
- node_id(node)
9
- end
10
-
11
- def occurences
12
- node_occurences(node)
13
- end
14
-
15
- private
16
-
17
- attr_reader :node
18
-
19
- def node_id(node)
20
- node.children.map do |n|
21
- node_id(n)
22
- end.reduce(:+).to_a.push({ name: node.name, id: node.id })
23
- end
24
-
25
- def node_occurences(node)
26
- occurences = []
27
- occurences += node.children.map { |n| node_occurences(n) }.reduce([], :+)
28
-
29
- occurences += node.occurences.map { |n| {source: node.id, target: n.id } }.to_a
30
- occurences
31
- end
32
- end
33
- end
data/lib/tree.rb DELETED
@@ -1,75 +0,0 @@
1
- module Rubrowser
2
- class Tree
3
- attr_reader :name, :children, :occurences, :parent
4
-
5
- def self.from_parsers(parsers)
6
- return Tree.new if parsers.empty?
7
-
8
- definitions = parsers.map(&:definitions).reduce([], :+).uniq
9
- occurences = parsers.map(&:occurences).reduce([], :+).uniq
10
- Tree.new.tap do |tree|
11
- definitions.each { |definition| tree.add_child(definition) }
12
- occurences.each { |occurence| tree.add_occurence(*occurence.first) }
13
- end
14
- end
15
-
16
- def initialize(name = 'Kernel', parent = nil)
17
- @name = name
18
- @parent = parent
19
- @children = Set.new
20
- @occurences = Set.new
21
- end
22
-
23
- def root?
24
- @parent.nil?
25
- end
26
-
27
- def id
28
- return name if root? || parent.root?
29
- "#{parent.id}::#{name}".to_sym
30
- end
31
-
32
- def add_child(child_name_path = [])
33
- return if child_name_path.empty?
34
- child = get_or_create_child(child_name_path[0])
35
- children.add(child)
36
- child.add_child(child_name_path[1..-1])
37
- end
38
-
39
- def add_occurence(user, constants)
40
- user_node = find_node(user)
41
- occured_node = constants.map { |constant| find_node(constant) }.compact.first
42
- return unless user_node && occured_node
43
- user_node.occurences << occured_node
44
- end
45
-
46
- def find_node(path)
47
- return self if path.empty?
48
- child = children.find { |c| c.name == path.first }
49
- return unless child
50
- child.find_node(path[1..-1])
51
- end
52
-
53
- def get_or_create_child(child_name)
54
- children.find { |child| child_name == child.name } || Tree.new(child_name, self)
55
- end
56
-
57
- def eq?(other)
58
- other.name == name
59
- end
60
-
61
- def to_h
62
- {
63
- id: id,
64
- name: name
65
- }.tap do |hash|
66
- hash[:children] = children.map(&:to_h) unless children.empty?
67
- hash[:occurences] = occurences.map(&:id) unless occurences.empty?
68
- end
69
- end
70
-
71
- private
72
-
73
- attr_writer :occurences
74
- end
75
- end