rubrowser 0.2.6 → 0.2.7

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: f94392243bcd5643136643e838c1d43382c9437e
4
- data.tar.gz: e8c90eb45c0a7ae4656f0cfc173a58c7f1be89d7
3
+ metadata.gz: fd6da7e91cc1f4b7e50ba33d062baa579f2054d5
4
+ data.tar.gz: 400349b68d33f44c42c0b7571318eab0ec675c96
5
5
  SHA512:
6
- metadata.gz: b0edd936a9bf980e79e3c796546fc25912235bd5038562128ab1e600baf72c8483982a7e8353ab1337762867b94010efd4cd7592bab3417ad9c962d988d05ff3
7
- data.tar.gz: 615030ae5b7314b49110e5dfc60141969e414ae3d6d2ae29d319af2edf5d03085801e0d7db1a63c03ddf08a4563114f2fb52377606d0a4ecdea40528dcdf02f6
6
+ metadata.gz: be689e37c1507f092ad03e735e78e6464b2f63100e42c134e70fda6350277881cb5ab87d812a34504928bd3e6be72db8565712c9b5731261804159d73ff5650a
7
+ data.tar.gz: b21b259b207cabe0c822012a04b4e6ecdc5070685403c94d35f0712d61c47a8ad74b70465893d33e48f1e599ea91f8c95fa347ab2a273042f103a7edbbb3f9fd
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
- tmp/
1
+ tmp/
2
+ pkg/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubrowser (0.2.6)
4
+ rubrowser (0.2.7)
5
5
  parser (~> 2.3, >= 2.3.0)
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ module Rubrowser
9
9
  end
10
10
 
11
11
  def definitions
12
- @_constants ||= parsers.map(&:definitions).reduce(:+).to_a
12
+ @_definitions ||= parsers.map(&:definitions).reduce(:+).to_a
13
13
  end
14
14
 
15
15
  def relations
@@ -18,15 +18,15 @@ module Rubrowser
18
18
 
19
19
  private
20
20
 
21
+ attr_reader :files, :parsed
22
+ alias parsed? parsed
23
+
21
24
  def parse
22
25
  return if parsed?
23
26
  parsers.each(&:parse)
24
27
  @parsed = true
25
28
  end
26
29
 
27
- attr_reader :files, :parsed
28
- alias parsed? parsed
29
-
30
30
  def parsers
31
31
  @_parsers ||= files.map do |file|
32
32
  Rubrowser::Parser::Factory.build(file)
@@ -23,7 +23,8 @@ module Rubrowser
23
23
  type: demoularize(definition.class.name),
24
24
  namespace: definition.to_s,
25
25
  file: definition.file,
26
- line: definition.line
26
+ line: definition.line,
27
+ lines: definition.lines
27
28
  }
28
29
  end
29
30
 
@@ -2,12 +2,13 @@ module Rubrowser
2
2
  module Parser
3
3
  module Definition
4
4
  class Base
5
- attr_reader :namespace, :file, :line
5
+ attr_reader :namespace, :file, :line, :lines
6
6
 
7
- def initialize(namespace, file: nil, line: nil)
7
+ def initialize(namespace, file: nil, line: nil, lines: 0)
8
8
  @namespace = Array(namespace)
9
9
  @file = file
10
10
  @line = line
11
+ @lines = lines
11
12
  end
12
13
 
13
14
  def name
@@ -0,0 +1,15 @@
1
+ module Rubrowser
2
+ module Parser
3
+ class File
4
+ # This class is a workaround for this behaviour
5
+ # https://github.com/whitequark/parser/commit/95401a20e8f4532e32f6361da3918ac8e4bd18c7
6
+ # the snippet that is using this class in File is copied from:
7
+ # https://github.com/eapache/starscope/pull/166/files
8
+ class Builder < ::Parser::Builders::Default
9
+ def string_value(token)
10
+ value(token)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,7 +2,7 @@ require 'parser/current'
2
2
  require 'rubrowser/parser/definition/class'
3
3
  require 'rubrowser/parser/definition/module'
4
4
  require 'rubrowser/parser/relation/base'
5
- require 'rubrowser/parser/builder'
5
+ require 'rubrowser/parser/file/builder'
6
6
 
7
7
  module Rubrowser
8
8
  module Parser
@@ -18,22 +18,21 @@ module Rubrowser
18
18
  end
19
19
 
20
20
  def parse
21
- if valid_file?(file)
22
- contents = ::File.read(file)
21
+ return unless valid_file?(file)
22
+ contents = ::File.read(file)
23
23
 
24
- buffer = ::Parser::Source::Buffer.new(file, 1)
25
- buffer.source = contents.force_encoding(Encoding::UTF_8)
24
+ buffer = ::Parser::Source::Buffer.new(file, 1)
25
+ buffer.source = contents.force_encoding(Encoding::UTF_8)
26
26
 
27
- parser = ::Parser::CurrentRuby.new(Builder.new)
28
- parser.diagnostics.ignore_warnings = true
29
- parser.diagnostics.all_errors_are_fatal = false
27
+ parser = ::Parser::CurrentRuby.new(Builder.new)
28
+ parser.diagnostics.ignore_warnings = true
29
+ parser.diagnostics.all_errors_are_fatal = false
30
30
 
31
- ast = parser.parse(buffer)
32
- constants = parse_block(ast)
31
+ ast = parser.parse(buffer)
32
+ constants = parse_block(ast)
33
33
 
34
- @definitions = constants[:definitions]
35
- @relations = constants[:relations]
36
- end
34
+ @definitions = constants[:definitions]
35
+ @relations = constants[:relations]
37
36
  rescue ::Parser::SyntaxError
38
37
  warn "SyntaxError in #{file}"
39
38
  end
@@ -62,7 +61,8 @@ module Rubrowser
62
61
  definition = Definition::Module.new(
63
62
  namespace,
64
63
  file: file,
65
- line: node.loc.line
64
+ line: node.loc.line,
65
+ lines: node.loc.last_line - node.loc.line + 1
66
66
  )
67
67
  constants = { definitions: [definition] }
68
68
  children_constants = parse_array(node.children[1..-1], namespace)
@@ -75,7 +75,8 @@ module Rubrowser
75
75
  definition = Definition::Class.new(
76
76
  namespace,
77
77
  file: file,
78
- line: node.loc.line
78
+ line: node.loc.line,
79
+ lines: node.loc.last_line - node.loc.line + 1
79
80
  )
80
81
  constants = { definitions: [definition] }
81
82
  children_constants = parse_array(node.children[1..-1], namespace)
@@ -35,9 +35,11 @@ module Rubrowser
35
35
  private
36
36
 
37
37
  def possibilities
38
- return [
39
- Definition::Base.new(@namespace.compact, file: file, line: line)
40
- ] if absolute?
38
+ if absolute?
39
+ return [
40
+ Definition::Base.new(@namespace.compact, file: file, line: line)
41
+ ]
42
+ end
41
43
 
42
44
  possible_parent_namespaces
43
45
  .map { |possible_parent| possible_parent + @namespace }
@@ -5,16 +5,23 @@ require 'rubrowser/formatter/json'
5
5
 
6
6
  module Rubrowser
7
7
  class Server < WEBrick::HTTPServer
8
+ # Accepted options are:
9
+ # port: port number for the server
10
+ # files: list of file paths to parse
11
+ def self.start(options = {})
12
+ new(options).start
13
+ end
14
+
15
+ private
16
+
8
17
  include ERB::Util
9
18
 
10
19
  ROUTES = {
11
20
  '/' => :root,
12
21
  '/data.json' => :data
13
- }
22
+ }.freeze
14
23
 
15
- def self.start(options = {})
16
- new(options).start
17
- end
24
+ attr_reader :files
18
25
 
19
26
  def initialize(options)
20
27
  super Port: options[:port]
@@ -25,10 +32,6 @@ module Rubrowser
25
32
  end
26
33
  end
27
34
 
28
- private
29
-
30
- attr_reader :files
31
-
32
35
  def router(path)
33
36
  return file(path) if file?(path)
34
37
  return send(ROUTES[path]) if ROUTES.key?(path)
@@ -1,3 +1,3 @@
1
1
  module Rubrowser
2
- VERSION = '0.2.6'.freeze
2
+ VERSION = '0.2.7'.freeze
3
3
  end
@@ -12,10 +12,19 @@ var parseGraph = function(data){
12
12
  drag = d3.drag()
13
13
  .on("start", dragstarted)
14
14
  .on("drag", dragged)
15
- .on("end", dragended),
16
- definitions = _.uniqWith(data.definitions.map(function(d){ return {id: d.namespace, type: d.type }; }), _.isEqual),
15
+ .on("end", dragended),
16
+ dup_definitions = data.definitions.map(function(d){ return {id: d.namespace, type: d.type, lines: d.lines }; }),
17
+ definitions = _(dup_definitions).groupBy('id').map(function(group) {
18
+ return {
19
+ id: group[0].id,
20
+ type: group[0].type,
21
+ lines: _(group).sumBy('lines')
22
+ };
23
+ }).value(),
17
24
  namespaces = definitions.map(function(d){ return d.id; }),
18
- relations = data.relations.map(function(d){ return {source: d.caller, target: d.resolved_namespace }; });
25
+ relations = data.relations.map(function(d){ return {source: d.caller, target: d.resolved_namespace }; }),
26
+ max_lines = _.maxBy(definitions, 'lines').lines,
27
+ max_circle_r = 50;
19
28
 
20
29
  relations = relations.filter(function(d){
21
30
  return namespaces.indexOf(d.source) >= 0 && namespaces.indexOf(d.target) >= 0;
@@ -50,7 +59,7 @@ var parseGraph = function(data){
50
59
  .data(relations)
51
60
  .enter().append("path")
52
61
  .attr("class", 'link')
53
- .attr("marker-end", "url(#relation)"),
62
+ .attr("marker-end", function(d){ return "url(#" + d.target.id + ")"; }),
54
63
  node = container.append("g")
55
64
  .attr("class", "nodes")
56
65
  .selectAll("g")
@@ -60,7 +69,7 @@ var parseGraph = function(data){
60
69
  .on("dblclick", dblclick),
61
70
  circle = node
62
71
  .append("circle")
63
- .attr("r", 6),
72
+ .attr("r", function(d) { return d.lines / max_lines * max_circle_r + 6; }),
64
73
  type = node
65
74
  .append("text")
66
75
  .attr("class", "type")
@@ -70,17 +79,17 @@ var parseGraph = function(data){
70
79
  text = node
71
80
  .append("text")
72
81
  .attr("class", "namespace")
73
- .attr("x", 8)
82
+ .attr("x", function(d) { return d.lines / max_lines * max_circle_r + 8; })
74
83
  .attr("y", ".31em")
75
84
  .text(function(d) { return d.id; });
76
85
 
77
86
  container.append("defs").selectAll("marker")
78
- .data(['relation'])
87
+ .data(definitions)
79
88
  .enter().append("marker")
80
- .attr("id", function(d) { return d; })
89
+ .attr("id", function(d) { return d.id; })
81
90
  .attr("viewBox", "0 -5 10 10")
82
- .attr("refX", 15)
83
- .attr("refY", -1.5)
91
+ .attr("refX", function(d){ return d.lines / max_lines * max_circle_r + 20; })
92
+ .attr("refY", 0)
84
93
  .attr("markerWidth", 6)
85
94
  .attr("markerHeight", 6)
86
95
  .attr("orient", "auto")