society 0.13.1 → 0.13.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf50fdd42f46c181a66763f33c8d0d38bd82f525
4
- data.tar.gz: a1e251de6167da6145c18d12c6128096c50abf0e
3
+ metadata.gz: 8f65f593c46ae32062a78ec4c22aaf53f55f7436
4
+ data.tar.gz: 7f39c3d8b353ff9ad94568abcc690c90a5b878b7
5
5
  SHA512:
6
- metadata.gz: 9a9ac14f3d26fe5272defeca19d51b1815fb2187acd448c8313812c2e8de4702349e607758206743037329eb012fa47a46e74f361ec6896534706a007d528a6f
7
- data.tar.gz: 6d0444bb2921dc253d0f76c8754542fc4b0ba1ccb6e14fd12da2df4ed5f6e8595ca38a581631ff248118822c2ee94f87da6e370a49746faaa3376fbe27996731
6
+ metadata.gz: 109d6b030877005b7246c2702312cbac6213d9687b06d2e573ddfcb617cc5ec528f40db2799773800ba365666a965c0b8c3a60e49a2a23bfd8cf8c1af1001385
7
+ data.tar.gz: 46b91d5ee61b7056f8709d03b1d0dc607482b7d53ac6d758b2b3f8813b4035cf66aebfa9a65debcbf0d37283b02759c8f35ac7efb08c47d23e635d3e9f11b538
data/lib/society.rb CHANGED
@@ -3,7 +3,6 @@ require "fileutils"
3
3
  module Society
4
4
  end
5
5
 
6
- require_relative "society/analyzer"
7
6
  require_relative "society/cli"
8
7
  require_relative "society/matrix"
9
8
  require_relative "society/node"
@@ -24,7 +24,7 @@ module Society
24
24
  reference_matrix = [[]]
25
25
  nodes.each_with_index do |node, i|
26
26
  references = node_names.map do |name|
27
- node.references.include?(name) ? 1 : 0
27
+ node.edges.include?(name) ? 1 : 0
28
28
  end
29
29
  reference_matrix.push(references)
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module Society
2
- VERSION = "0.13.1"
2
+ VERSION = "0.13.2"
3
3
  end
data/spec/matrix_spec.rb CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Society::Matrix do
4
4
 
5
- let(:node) { Struct.new(:name, :references)}
5
+ let(:node) { Struct.new(:name, :edges) }
6
6
  let(:nodes) {
7
7
  [
8
8
  node.new("foo", %w{bar bat baz}),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: society
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coraline Ada Ehmke
@@ -169,7 +169,6 @@ files:
169
169
  - Rakefile
170
170
  - bin/society
171
171
  - lib/society.rb
172
- - lib/society/analyzer.rb
173
172
  - lib/society/cli.rb
174
173
  - lib/society/matrix.rb
175
174
  - lib/society/node.rb
@@ -177,7 +176,6 @@ files:
177
176
  - lib/society/parser.rb
178
177
  - lib/society/version.rb
179
178
  - society.gemspec
180
- - spec/analyzer_spec.rb
181
179
  - spec/fixtures/bar.rb
182
180
  - spec/fixtures/foo.rb
183
181
  - spec/matrix_spec.rb
@@ -208,7 +206,6 @@ signing_key:
208
206
  specification_version: 4
209
207
  summary: Social graph for Ruby objects
210
208
  test_files:
211
- - spec/analyzer_spec.rb
212
209
  - spec/fixtures/bar.rb
213
210
  - spec/fixtures/foo.rb
214
211
  - spec/matrix_spec.rb
@@ -1,134 +0,0 @@
1
- require 'parser/current'
2
- require 'pry'
3
-
4
- module Society
5
-
6
- class Analyzer
7
-
8
- attr_reader :content
9
-
10
- DEFAULT_CLASS_NAME = "Unknown"
11
-
12
- def initialize(content)
13
- @content = content
14
- end
15
-
16
- def class_name
17
- find_class(parsed) || DEFAULT_CLASS_NAME
18
- end
19
-
20
- def methods
21
- @methods ||= methods_from(parsed)
22
- end
23
-
24
- def constants
25
- @constants ||= constants_from(parsed)
26
- end
27
-
28
- private
29
-
30
- def method_list
31
- @method_list ||= method_names_from(parsed.children.first)
32
- end
33
-
34
- def method_names_from(node, found=[])
35
- if node.type == :def || node.type == :defs
36
- name = node.loc.name
37
- found << content[name.begin_pos..name.end_pos - 1].to_sym
38
- end
39
- node.children.each do |child|
40
- method_names_from(child, found) if parent_node?(child)
41
- end
42
- found
43
- end
44
-
45
- def constants_from(node, found=[])
46
- if node.type == :const
47
- expression = node.loc.expression
48
- found << content[expression.begin_pos..expression.end_pos - 1]
49
- end
50
- node.children.each do |child|
51
- constants_from(child, found) if parent_node?(child)
52
- end
53
- found.reject{ |constant| constant == class_name }
54
- end
55
-
56
- def find_class(node)
57
- return unless node && node.respond_to?(:type)
58
- concat = []
59
- if node.type == :module || node.type == :class
60
- concat << text_at(node.loc.name.begin_pos, node.loc.name.end_pos)
61
- end
62
- concat << node.children.map{|child| find_class(child)}.compact
63
- concat.flatten.reject(&:empty?).join('::')
64
- end
65
-
66
- def extract_references_from(node, found=[])
67
- return found unless node && node.respond_to?(:type)
68
- if node.type == :send
69
- reference = node.loc.expression
70
- found << node.children.last
71
- end
72
- node.children.each do |child|
73
- extract_references_from(child, found)
74
- end
75
- found.select{|name| method_list.include?(name)}
76
- end
77
-
78
- def methods_from(node, found=[])
79
- if node.type == :def || node.type == :defs
80
- name = node.loc.name
81
- expression = node.loc.expression
82
- type = case(node.type)
83
- when :defs
84
- :class
85
- when :def
86
- :instance
87
- when :class
88
- :none
89
- end
90
- found << ParsedMethod.new(
91
- name: content[name.begin_pos..name.end_pos - 1],
92
- content: content[expression.begin_pos..expression.end_pos - 1],
93
- type: type,
94
- refs: extract_references_from(node)
95
- )
96
- end
97
- node.children.each do |child|
98
- if parent_node?(child)
99
- methods_from(child, found)
100
- end
101
- end
102
- found
103
- end
104
-
105
- def parent_node?(node)
106
- node.respond_to?(:type) || node.respond_to?(:children)
107
- end
108
-
109
- def parse!
110
- traverse(parsed) && complexity
111
- end
112
-
113
- def parsed
114
- @parsed ||= ::Parser::CurrentRuby.parse(content)
115
- end
116
-
117
- def text_at(start_pos, end_pos)
118
- content[start_pos..end_pos - 1]
119
- end
120
-
121
- def traverse(node, accumulator=[], extract_methods=false)
122
- accumulator << node.type
123
- node.children.each do |child|
124
- if parent_node?(child)
125
- accumulator << child.type
126
- traverse(child, accumulator)
127
- end
128
- end
129
- accumulator
130
- end
131
-
132
- end
133
-
134
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Society::Analyzer do
4
-
5
- let(:source) { File.open("./spec/fixtures/foo.rb", "r").read }
6
- let(:analyzer) { Society::Analyzer.new(source) }
7
-
8
- describe "#initialize" do
9
- it "assigns its content" do
10
- expect(analyzer.content).to eq(source)
11
- end
12
- end
13
-
14
- describe "#class_name" do
15
- xit "doesn't get confused by multiple class declarations in one file"
16
-
17
- it "returns a class name" do
18
- expect(analyzer.class_name).to eq "Foo"
19
- end
20
- end
21
-
22
- describe "#methods" do
23
- it "returns a list of methods from its source" do
24
- expected = ["#penultimate_method", "#initial_method", "#external_call", "#ultimate_method"]
25
- expect(analyzer.methods.map(&:name)).to eq(expected)
26
- end
27
- end
28
-
29
- describe "constants" do
30
- it "returns a list of classes" do
31
- expected = ["Bar"]
32
- expect(analyzer.constants).to eq(expected)
33
- end
34
- end
35
-
36
- end