seven_bridges 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a26e6a0424fb15dd2c5f9a9e3720bd199aa021e2
4
+ data.tar.gz: 56d8ee4257e9ae93b1adaedaaaf7a9caa2462342
5
+ SHA512:
6
+ metadata.gz: 38f109a30b43d6511b9025d013d49b3fbe27182a24316821ed5c0c3b4d3e0dbc97df87d9fbf8ebefcf689a40d3d4bb68ff0b44c6afa2fd0c119799b1ef15737e
7
+ data.tar.gz: 28e81e73eff1c6c8b43fa4e1576c1c15246ad5cd3a0a05facb080d6e27c5a63dc012211ffdf93e2e4803651ad10d27ea57853374894e122650e0f5e5b9165f4c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.3
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in seven_bridges.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "activesupport"
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Scott Speidel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # SevenBridges
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/seven_bridges`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'seven_bridges'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install seven_bridges
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/seven_bridges.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.warning = false
8
+ t.test_files = FileList['test/seven_bridges/**/*_test.rb']
9
+ end
10
+
11
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "seven_bridges"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,101 @@
1
+ require 'neo4j'
2
+ require 'seven_bridges/method'
3
+ require 'seven_bridges/call'
4
+ require 'seven_bridges/called_by'
5
+ require 'seven_bridges/test_method'
6
+ require 'seven_bridges/neo4j_store'
7
+ require 'seven_bridges/memory_store'
8
+ require 'seven_bridges/memory_store_csv_dumper'
9
+
10
+ module SevenBridges
11
+ class << self
12
+ attr_writer :klass, :project_root, :store
13
+
14
+ def klass
15
+ @klass ||= Minitest::Test
16
+ end
17
+
18
+ def project_root
19
+ @project_root ||= ''
20
+ end
21
+
22
+ def store
23
+ @store ||= SevenBridges::Neo4jStore.new
24
+ end
25
+
26
+ def configure
27
+ yield self
28
+
29
+ klass.class_eval do
30
+ alias_method :setup_without_trace, :setup
31
+ alias_method :teardown_without_trace, :teardown
32
+
33
+ def setup
34
+ setup_without_trace
35
+ @callstack = []
36
+ @trace = TracePoint.new(:call) do |tp|
37
+ if tp.path.start_with? SevenBridges.project_root
38
+ path = make_path(tp)
39
+ if !path.end_with?('#teardown')
40
+ find_location_and_build_graph path
41
+ end
42
+ end
43
+ end
44
+ @trace.enable
45
+ end
46
+
47
+ private
48
+
49
+ def make_path(tp)
50
+ "#{strip_project_root(tp.path)}##{tp.method_id}"
51
+ end
52
+
53
+ def get_or_create_current_node(path)
54
+ current = SevenBridges.store.find_method(path)
55
+ return current if current.present?
56
+
57
+ return SevenBridges.store.create_test_method_node(get_method_name(path), path) if @callstack.empty?
58
+ return SevenBridges.store.create_method_node(get_method_name(path), path)
59
+ end
60
+
61
+ def find_location_and_build_graph(path)
62
+ find_parent
63
+ current = get_or_create_current_node(path)
64
+ add_calling_relationship current
65
+ create_stack_frame current
66
+ end
67
+
68
+ def create_stack_frame(current)
69
+ @callstack << { node: current, level: caller.size }
70
+ end
71
+
72
+ def add_calling_relationship(current)
73
+ return if @callstack.empty?
74
+
75
+ SevenBridges.store.add_relationship(:calls, @callstack.last[:node], current)
76
+ SevenBridges.store.add_relationship(:called_by, current, @callstack.first[:node])
77
+ end
78
+
79
+ def find_parent
80
+ while(!@callstack.empty? && caller.size <= @callstack.last[:level]) do
81
+ @callstack.pop
82
+ end
83
+ end
84
+
85
+ def teardown
86
+ @trace.disable
87
+ @callstack = []
88
+ teardown_without_trace
89
+ end
90
+
91
+ def get_method_name(path)
92
+ path.split('#')[1]
93
+ end
94
+
95
+ def strip_project_root(path)
96
+ path[SevenBridges.project_root.length..-1]
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,13 @@
1
+ require 'neo4j'
2
+
3
+ module SevenBridges
4
+ class Call
5
+ include Neo4j::ActiveRel
6
+ from_class 'SevenBridges::Method'
7
+ to_class 'SevenBridges::Method'
8
+
9
+ creates_unique
10
+
11
+ type 'calls'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'neo4j'
2
+
3
+ module SevenBridges
4
+ class CalledBy
5
+ include Neo4j::ActiveRel
6
+ from_class 'SevenBridges::Method'
7
+ to_class 'SevenBridges::Method'
8
+
9
+ creates_unique
10
+
11
+ type 'called_by'
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ module SevenBridges
2
+ class MemoryStore
3
+ def initialize
4
+ @nodes = {}
5
+ @edges = {}
6
+ end
7
+
8
+ def edges
9
+ @edges.keys
10
+ end
11
+
12
+ def nodes
13
+ @nodes.values
14
+ end
15
+
16
+ def find_method(path)
17
+ @nodes[path]
18
+ end
19
+
20
+ def create_test_method_node(method_name, path)
21
+ @nodes[path] ||= {name: method_name, path: path, type: 'test'}
22
+ end
23
+
24
+ def create_method_node(method_name, path)
25
+ @nodes[path] ||= {name: method_name, path: path, type: 'app'}
26
+ end
27
+
28
+ def add_relationship(label, from, to)
29
+ @edges[{label: label, from: from[:path], to: to[:path]}] = 1
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,54 @@
1
+ require 'csv'
2
+ require 'fileutils'
3
+
4
+ module SevenBridges
5
+ class MemoryStoreCSVDumper
6
+
7
+ def initialize(memory_store, base_path)
8
+ @store = memory_store
9
+ @base_path = base_path
10
+ end
11
+
12
+ def dump
13
+ FileUtils.mkdir_p(@base_path)
14
+
15
+ CSV.open(nodes_header_file, "wb") do |csv|
16
+ csv << ["path:ID", "name", ":LABEL"]
17
+ end
18
+
19
+ CSV.open(nodes_file, "wb") do |csv|
20
+ @store.nodes.each do |node|
21
+ csv << [node[:path], node[:name], ((node[:type] == 'app') ? "METHOD" : "TEST_METHOD")]
22
+ end
23
+ end
24
+
25
+ CSV.open(edges_header_file, "wb") do |csv|
26
+ csv << [":START_ID", ":END_ID", ":TYPE"]
27
+ end
28
+
29
+ CSV.open(edges_file, "wb") do |csv|
30
+ @store.edges.each do |edge|
31
+ csv << [edge[:from], edge[:to], edge[:label]]
32
+ end
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def nodes_header_file
39
+ File.join(@base_path, "nodes_header.csv")
40
+ end
41
+
42
+ def nodes_file
43
+ File.join(@base_path, "nodes.csv")
44
+ end
45
+
46
+ def edges_header_file
47
+ File.join(@base_path, "relationships_header.csv")
48
+ end
49
+
50
+ def edges_file
51
+ File.join(@base_path, "relationships.csv")
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,18 @@
1
+ require 'neo4j'
2
+
3
+ module SevenBridges
4
+ class Method
5
+ include Neo4j::ActiveNode
6
+ #self.mapped_label_name = 'Method'
7
+ property :name
8
+ property :path, index: :exact
9
+ property :type
10
+ # property :num_incoming_refs, type: Integer, default: 0
11
+
12
+ validates :path, presence: true
13
+ validates :type, presence: true
14
+ #validates :num_incoming_refs, numericality: { only_integer: true }
15
+ has_many :out, :calls , rel_class: 'SevenBridges::Call', model_class: 'SevenBridges::Method'
16
+ has_many :out, :called_by, rel_class: 'SevenBridges::CalledBy', model_class: 'SevenBridges::TestMethod'
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module SevenBridges
2
+ class Neo4jStore
3
+
4
+ def find_method(path)
5
+ Method.find_by(path: path)
6
+ end
7
+
8
+ def create_test_method_node(method_name, path)
9
+ TestMethod.create(name: method_name, path: path, type: 'test')
10
+ end
11
+
12
+ def create_method_node(method_name, path)
13
+ Method.create(name: method_name, path: path, type: 'app')
14
+ end
15
+
16
+ def add_relationship(label, from, to)
17
+ from.public_send(label) << to
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ require 'neo4j'
2
+ module SevenBridges
3
+ class TestMethod < SevenBridges::Method
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module SevenBridges
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'seven_bridges/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'seven_bridges'
8
+ spec.version = SevenBridges::VERSION
9
+ spec.authors = ['Scott Speidel', 'Michael Jewell', 'Stanley Fung']
10
+ spec.email = ['scottspeidel@gmail.com', 'michaeljewell9911@gmail.com']
11
+
12
+ spec.summary = 'Tool to help understand the relationships between ruby methods'
13
+ spec.description = ''
14
+ spec.homepage = 'https://github.com/appfolio/seven_bridges'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.11'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'minitest', '~> 5.0'
25
+ spec.add_dependency 'neo4j'
26
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seven_bridges
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Scott Speidel
8
+ - Michael Jewell
9
+ - Stanley Fung
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2016-04-22 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.11'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.11'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: minitest
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '5.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '5.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: neo4j
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ description: ''
72
+ email:
73
+ - scottspeidel@gmail.com
74
+ - michaeljewell9911@gmail.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".ruby-version"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/seven_bridges.rb
89
+ - lib/seven_bridges/call.rb
90
+ - lib/seven_bridges/called_by.rb
91
+ - lib/seven_bridges/memory_store.rb
92
+ - lib/seven_bridges/memory_store_csv_dumper.rb
93
+ - lib/seven_bridges/method.rb
94
+ - lib/seven_bridges/neo4j_store.rb
95
+ - lib/seven_bridges/test_method.rb
96
+ - lib/seven_bridges/version.rb
97
+ - seven_bridges.gemspec
98
+ homepage: https://github.com/appfolio/seven_bridges
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.5.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Tool to help understand the relationships between ruby methods
122
+ test_files: []
123
+ has_rdoc: