society 0.13.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.bowerrc +3 -0
  3. data/.gitignore +2 -14
  4. data/README.md +18 -17
  5. data/bower.json +6 -0
  6. data/lib/society.rb +16 -6
  7. data/lib/society/association_processor.rb +206 -0
  8. data/lib/society/cli.rb +12 -9
  9. data/lib/society/edge.rb +15 -0
  10. data/lib/society/formatter/graph/json.rb +44 -0
  11. data/lib/society/formatter/report/html.rb +73 -0
  12. data/lib/society/formatter/report/json.rb +39 -0
  13. data/lib/society/formatter/report/templates/components/.gitignore +7 -0
  14. data/lib/society/formatter/report/templates/components/d3/d3.min.js +5 -0
  15. data/lib/society/formatter/report/templates/components/society-assets/society.css +70 -0
  16. data/lib/society/formatter/report/templates/components/society-assets/society.js +420 -0
  17. data/lib/society/formatter/report/templates/index.htm.haml +48 -0
  18. data/lib/society/object_graph.rb +3 -2
  19. data/lib/society/parser.rb +49 -32
  20. data/lib/society/reference_processor.rb +60 -0
  21. data/lib/society/version.rb +1 -1
  22. data/society.gemspec +4 -1
  23. data/society_graph.json +1 -0
  24. data/spec/association_processor_spec.rb +174 -0
  25. data/spec/cli_spec.rb +25 -0
  26. data/spec/fixtures/foo.rb +6 -18
  27. data/spec/formatter/graph/json_spec.rb +52 -0
  28. data/spec/formatter/report/html_spec.rb +75 -0
  29. data/spec/formatter/report/json_spec.rb +70 -0
  30. data/spec/object_graph_spec.rb +30 -0
  31. data/spec/parser_spec.rb +61 -0
  32. data/spec/reference_processor_spec.rb +18 -0
  33. data/spec/spec_helper.rb +3 -0
  34. metadata +77 -13
  35. data/lib/society/matrix.rb +0 -36
  36. data/lib/society/node.rb +0 -19
  37. data/spec/fixtures/bar.rb +0 -6
  38. data/spec/matrix_spec.rb +0 -27
  39. data/spec/node_spec.rb +0 -30
data/spec/fixtures/foo.rb CHANGED
@@ -1,22 +1,10 @@
1
- class Foo
1
+ class Whaler
2
2
 
3
- def penultimate_method
4
- ultimate_method
5
- end
6
-
7
- def initial_method
8
- penultimate_method
9
- penultimate_method
10
- penultimate_method
11
- end
3
+ attr_accessor :name, :position
12
4
 
13
- def external_call
14
- Bar.new.say_hello
5
+ def initialize(name:, position: )
6
+ @name = name
7
+ @position = position
15
8
  end
16
9
 
17
- private
18
-
19
- def ultimate_method
20
- self.to_s
21
- end
22
- end
10
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'analyst'
3
+
4
+ describe Society::Formatter::Graph::JSON do
5
+
6
+ let(:graph) { Struct.new(:nodes, :edges)}
7
+ let(:node) { Struct.new(:full_name) }
8
+ let(:edge) { Struct.new(:from, :to) }
9
+
10
+ let(:node_instance_1) { node.new("sample_node")}
11
+ let(:node_instance_2) { node.new("other_node")}
12
+ let(:edge_instance) { edge.new(node_instance_1, node_instance_2) }
13
+
14
+ let(:graph_instance) { graph.new(
15
+ [node_instance_1, node_instance_2],
16
+ [edge_instance]
17
+ )
18
+ }
19
+
20
+ let(:formatter) { Society::Formatter::Graph::JSON.new(graph_instance) }
21
+
22
+ describe "#to_hash" do
23
+
24
+ let(:hash) { formatter.to_hash }
25
+
26
+ context "returns a hash" do
27
+ it "with properly formatted nodes" do
28
+ expect(hash[:nodes]).to eq(
29
+ [
30
+ {name: "sample_node"},
31
+ {name: "other_node"}
32
+ ]
33
+ )
34
+ end
35
+
36
+ it "with properly formatted edges" do
37
+ expect(hash[:edges]).to eq([{from: 0, to: 1}])
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#to_json" do
43
+
44
+ let(:json) { formatter.to_json }
45
+ let(:hash) { formatter.to_hash }
46
+
47
+ it "returns json string for the result of #to_hash" do
48
+ expect(json).to eq hash.to_json
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe Society::Formatter::Report::HTML do
4
+
5
+ before do # don't actually change the filesystem
6
+ allow(FileUtils).to receive(:mkpath)
7
+ allow(File).to receive(:open)
8
+ end
9
+
10
+ let(:json_data) { {foo: 'bar'}.to_json }
11
+
12
+ describe "(private) #prepare_output_directory" do
13
+
14
+ context "with output directory specified" do
15
+
16
+ let(:output_directory) { "./doc" }
17
+ let(:report) do
18
+ Society::Formatter::Report::HTML.new(
19
+ json_data: json_data,
20
+ output_path: output_directory
21
+ )
22
+ end
23
+
24
+ it "creates the output directory" do
25
+ output_directory_matcher = Regexp.new(output_directory)
26
+ expect(FileUtils).to receive(:mkpath).with(output_directory_matcher)
27
+ report.send(:prepare_output_directory)
28
+ end
29
+ end
30
+
31
+ context "with no output directory specified" do
32
+
33
+ let(:default_directory) { File.join(%w[doc society]) }
34
+ let(:report) do
35
+ Society::Formatter::Report::HTML.new(
36
+ json_data: json_data
37
+ )
38
+ end
39
+
40
+ it "creates the default output directory" do
41
+ default_directory_matcher = Regexp.new(default_directory)
42
+ expect(FileUtils).to receive(:mkpath).with(default_directory_matcher)
43
+ report.send(:prepare_output_directory)
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "#write" do
49
+ let(:output_directory) { "./doc" }
50
+ let(:report) do
51
+ Society::Formatter::Report::HTML.new(
52
+ json_data: json_data,
53
+ output_path: output_directory
54
+ )
55
+ end
56
+ let(:society_css_path) { Regexp.new(File.join(%w[society-assets society.css])) }
57
+ let(:society_js_path) { Regexp.new(File.join(%w[society-assets society.js])) }
58
+ let(:d3_js_path) { Regexp.new(File.join(%w[d3 d3.min.js])) }
59
+ let(:output_directory_matcher) { Regexp.new(output_directory) }
60
+
61
+ it "copies bower assets to output dir" do
62
+ expect(FileUtils).to receive(:cp).with(society_css_path, output_directory_matcher)
63
+ expect(FileUtils).to receive(:cp).with(society_js_path, output_directory_matcher)
64
+ expect(FileUtils).to receive(:cp).with(d3_js_path, output_directory_matcher)
65
+ report.write
66
+ end
67
+
68
+ it "writes the html index file" do
69
+ index_path_matcher = Regexp.new('index.htm')
70
+ expect(File).to receive(:open).with(index_path_matcher, 'w')
71
+ report.write
72
+ end
73
+ end
74
+ end
75
+
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Society::Formatter::Report::Json do
4
+
5
+ before do # don't actually change the filesystem
6
+ allow(FileUtils).to receive(:mkpath)
7
+ allow(File).to receive(:open)
8
+ end
9
+
10
+ let(:json_data) { {foo: 'bar'}.to_json }
11
+
12
+ describe "(private) #prepare_output_directory" do
13
+ context "with output path specified" do
14
+
15
+ let(:output_path) { File.join(%w[blah mah_data.json]) }
16
+ let(:report) do
17
+ Society::Formatter::Report::Json.new(
18
+ json_data: json_data,
19
+ output_path: output_path
20
+ )
21
+ end
22
+
23
+ it "creates the output directory" do
24
+ output_directory_matcher = /blah/
25
+ expect(FileUtils).to receive(:mkpath).with(output_directory_matcher)
26
+ report.send(:prepare_output_directory)
27
+ end
28
+ end
29
+
30
+ context "with no output path specified" do
31
+
32
+ let(:default_output_directory) { File.join(%w[doc society TIMESTAMP]) }
33
+ let(:report) do
34
+ Society::Formatter::Report::Json.new(
35
+ json_data: json_data
36
+ )
37
+ end
38
+
39
+ it "creates the default directory" do
40
+ private_timestamp = report.send(:timestamp)
41
+ output_directory = default_output_directory.gsub('TIMESTAMP', private_timestamp)
42
+ default_directory_matcher = Regexp.new(output_directory)
43
+
44
+ expect(FileUtils).to receive(:mkpath).with(default_directory_matcher)
45
+ report.send(:prepare_output_directory)
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "#write" do
51
+
52
+ let(:output_path) { File.join(%w[blah mah_data.json]) }
53
+ let(:report) do
54
+ Society::Formatter::Report::Json.new(
55
+ json_data: json_data,
56
+ output_path: output_path
57
+ )
58
+ end
59
+
60
+ let(:open_file) { double }
61
+
62
+ it "writes the json data" do
63
+ expect(File).to receive(:open).with(output_path, 'w') do |path, mode, &block|
64
+ block.yield open_file
65
+ end
66
+ expect(open_file).to receive(:write).with(json_data)
67
+ report.write
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'analyst'
3
+
4
+ describe Society::ObjectGraph do
5
+
6
+ let(:graph) { Struct.new(:nodes, :edges)}
7
+ let(:node) { Struct.new(:full_name) }
8
+ let(:edge) { Struct.new(:from, :to) }
9
+
10
+ let(:node_instance_1) { node.new("sample_node")}
11
+ let(:node_instance_2) { node.new("other_node")}
12
+ let(:edge_instance) { edge.new(node_instance_1, node_instance_2) }
13
+
14
+ let(:graph) { Society::ObjectGraph.new(
15
+ nodes: [node_instance_1, node_instance_2],
16
+ edges: [edge_instance]
17
+ )
18
+ }
19
+
20
+ describe "#initialize" do
21
+ it "initializes its nodes" do
22
+ expect(graph.nodes.first.full_name).to eq "sample_node"
23
+ end
24
+ it "initializes its edges" do
25
+ expect(graph.edges.first.to.full_name).to eq "other_node"
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Society::Parser do
4
+
5
+ describe "::for_files" do
6
+
7
+ it "returns a parser object" do
8
+ expect(Society::Parser.for_files('./spec/fixtures').class.name).to eq("Society::Parser")
9
+ end
10
+
11
+ it "initializes the parser with an Analyzer object" do
12
+ expect(Society::Parser.for_files('./spec/fixtures').analyzer.class.name).to eq("Analyst::Parser")
13
+ end
14
+
15
+ end
16
+
17
+ describe "::for_source" do
18
+
19
+ let(:source) { "class Ship; end" }
20
+
21
+ it "returns a parser object" do
22
+ expect(Society::Parser.for_source(source).class.name).to eq("Society::Parser")
23
+ end
24
+
25
+ it "initializes the parser with an Analyzer object" do
26
+ expect(Society::Parser.for_source(source).analyzer.class.name).to eq("Analyst::Parser")
27
+ end
28
+
29
+ end
30
+
31
+ describe "#report" do
32
+
33
+ let(:parser) { Society::Parser.new(nil) }
34
+ let(:formatter) { double.as_null_object }
35
+
36
+ before do
37
+ allow(parser).to receive(:json_data).and_return('{"json": "is kewl"}')
38
+ end
39
+
40
+ context "with a valid format given" do
41
+ it "instantiates a formatter" do
42
+ expect(Society::Formatter::Report::HTML).to receive(:new).and_return(formatter)
43
+ parser.report(:html)
44
+ end
45
+
46
+ it "triggers the formatter to write its results" do
47
+ allow(Society::Formatter::Report::Json).to receive(:new).and_return(formatter)
48
+ expect(formatter).to receive(:write)
49
+ parser.report(:json)
50
+ end
51
+ end
52
+
53
+ context "with an invalid format given" do
54
+ it "raises an ArgumentError" do
55
+ expect { parser.report(:haiku) }.to raise_error(ArgumentError)
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Society::ReferenceProcessor do
4
+
5
+ describe "#references" do
6
+
7
+ let(:proxy) { Struct.new(:name, :full_name, :constants, :constant_assignments) }
8
+ let(:avatar_1) { proxy.new("AnimalMan", "Red::AnimalMan", [], []) }
9
+ let(:avatar_2) { proxy.new("Arcane", "Rot::Arcane", [], []) }
10
+ let(:avatar_3) { proxy.new("SwampThing", "Green::SwampThing", [avatar_1, avatar_2], []) }
11
+ let(:processor) { Society::ReferenceProcessor.new([avatar_1, avatar_2, avatar_3]) }
12
+
13
+ it "returns referenced classes" do
14
+ expect(processor.references.map(&:to)).to eq([avatar_1, avatar_2])
15
+ end
16
+ end
17
+ end
18
+
data/spec/spec_helper.rb CHANGED
@@ -5,3 +5,6 @@ SimpleCov.start
5
5
  require 'rubygems'
6
6
  require 'rspec'
7
7
  require 'society'
8
+ require 'byebug'
9
+ require 'awesome_print'
10
+
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.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coraline Ada Ehmke
@@ -9,22 +9,36 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-22 00:00:00.000000000 Z
12
+ date: 2014-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: fukuzatsu
15
+ name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 1.0.5
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: analyst
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.0.0
21
35
  type: :runtime
22
36
  prerelease: false
23
37
  version_requirements: !ruby/object:Gem::Requirement
24
38
  requirements:
25
39
  - - ">="
26
40
  - !ruby/object:Gem::Version
27
- version: 1.0.5
41
+ version: 1.0.0
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: parser
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -151,6 +165,34 @@ dependencies:
151
165
  - - ">="
152
166
  - !ruby/object:Gem::Version
153
167
  version: '0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: byebug
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ - !ruby/object:Gem::Dependency
183
+ name: awesome_print
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
154
196
  description: Social graph for Ruby objects
155
197
  email:
156
198
  - coraline@instructure.com
@@ -160,6 +202,7 @@ executables:
160
202
  extensions: []
161
203
  extra_rdoc_files: []
162
204
  files:
205
+ - ".bowerrc"
163
206
  - ".gitignore"
164
207
  - ".rspec"
165
208
  - CODE_OF_CONDUCT.md
@@ -168,18 +211,34 @@ files:
168
211
  - README.md
169
212
  - Rakefile
170
213
  - bin/society
214
+ - bower.json
171
215
  - lib/society.rb
216
+ - lib/society/association_processor.rb
172
217
  - lib/society/cli.rb
173
- - lib/society/matrix.rb
174
- - lib/society/node.rb
218
+ - lib/society/edge.rb
219
+ - lib/society/formatter/graph/json.rb
220
+ - lib/society/formatter/report/html.rb
221
+ - lib/society/formatter/report/json.rb
222
+ - lib/society/formatter/report/templates/components/.gitignore
223
+ - lib/society/formatter/report/templates/components/d3/d3.min.js
224
+ - lib/society/formatter/report/templates/components/society-assets/society.css
225
+ - lib/society/formatter/report/templates/components/society-assets/society.js
226
+ - lib/society/formatter/report/templates/index.htm.haml
175
227
  - lib/society/object_graph.rb
176
228
  - lib/society/parser.rb
229
+ - lib/society/reference_processor.rb
177
230
  - lib/society/version.rb
178
231
  - society.gemspec
179
- - spec/fixtures/bar.rb
232
+ - society_graph.json
233
+ - spec/association_processor_spec.rb
234
+ - spec/cli_spec.rb
180
235
  - spec/fixtures/foo.rb
181
- - spec/matrix_spec.rb
182
- - spec/node_spec.rb
236
+ - spec/formatter/graph/json_spec.rb
237
+ - spec/formatter/report/html_spec.rb
238
+ - spec/formatter/report/json_spec.rb
239
+ - spec/object_graph_spec.rb
240
+ - spec/parser_spec.rb
241
+ - spec/reference_processor_spec.rb
183
242
  - spec/spec_helper.rb
184
243
  homepage: https://github.com/Bantik/society
185
244
  licenses:
@@ -206,9 +265,14 @@ signing_key:
206
265
  specification_version: 4
207
266
  summary: Social graph for Ruby objects
208
267
  test_files:
209
- - spec/fixtures/bar.rb
268
+ - spec/association_processor_spec.rb
269
+ - spec/cli_spec.rb
210
270
  - spec/fixtures/foo.rb
211
- - spec/matrix_spec.rb
212
- - spec/node_spec.rb
271
+ - spec/formatter/graph/json_spec.rb
272
+ - spec/formatter/report/html_spec.rb
273
+ - spec/formatter/report/json_spec.rb
274
+ - spec/object_graph_spec.rb
275
+ - spec/parser_spec.rb
276
+ - spec/reference_processor_spec.rb
213
277
  - spec/spec_helper.rb
214
278
  has_rdoc: