log_require 0.1.0

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: 4aaf2298b38e7e53984adf32fa37f47e7be09684
4
+ data.tar.gz: 693dd61a3a0551afe4354a44846a44e0b7d726cf
5
+ SHA512:
6
+ metadata.gz: 5edf0918b1d41ab18d2057b4a076f3caaececd4c4ac48f8e6be01d856a66ffc2632dc973dd40df98590f41ac826cdaef3c1a75801480bf4e775c18054598b46d
7
+ data.tar.gz: c7b4421a7d82696c595f58ebc80392ad42208e2d47868ee3e50a1b3d97344d985c4f4b3c48dbfc94544f237deb4602473d9f2e6d177c89ad642e66204a4fbf14
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "yard", "~> 0.7"
5
+ gem "bundler", "~> 1.0"
6
+ gem "jeweler", "~> 2.0", :git => "https://github.com/chetan/jeweler.git", :branch => "bixby"
7
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ GIT
2
+ remote: https://github.com/chetan/jeweler.git
3
+ revision: b90381a3958daae7f3ce3d8c4d710fe39e72443b
4
+ branch: bixby
5
+ specs:
6
+ jeweler (2.0.1)
7
+ builder
8
+ bundler (>= 1.0)
9
+ git (>= 1.2.5)
10
+ github_api
11
+ highline (>= 1.6.15)
12
+ nokogiri (>= 1.5.10)
13
+ rake
14
+
15
+ GEM
16
+ remote: http://rubygems.org/
17
+ specs:
18
+ addressable (2.3.6)
19
+ builder (3.2.2)
20
+ descendants_tracker (0.0.4)
21
+ thread_safe (~> 0.3, >= 0.3.1)
22
+ faraday (0.9.0)
23
+ multipart-post (>= 1.2, < 3)
24
+ git (1.2.8)
25
+ github_api (0.12.2)
26
+ addressable (~> 2.3)
27
+ descendants_tracker (~> 0.0.4)
28
+ faraday (~> 0.8, < 0.10)
29
+ hashie (>= 3.3)
30
+ multi_json (>= 1.7.5, < 2.0)
31
+ nokogiri (~> 1.6.3)
32
+ oauth2
33
+ hashie (3.3.1)
34
+ highline (1.6.21)
35
+ jwt (1.0.0)
36
+ mini_portile (0.6.0)
37
+ multi_json (1.10.1)
38
+ multi_xml (0.5.5)
39
+ multipart-post (2.0.0)
40
+ nokogiri (1.6.3.1)
41
+ mini_portile (= 0.6.0)
42
+ oauth2 (1.0.0)
43
+ faraday (>= 0.8, < 0.10)
44
+ jwt (~> 1.0)
45
+ multi_json (~> 1.3)
46
+ multi_xml (~> 0.5)
47
+ rack (~> 1.2)
48
+ rack (1.5.2)
49
+ rake (10.3.2)
50
+ thread_safe (0.3.4)
51
+ yard (0.8.7.4)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ bundler (~> 1.0)
58
+ jeweler (~> 2.0)!
59
+ yard (~> 0.7)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Chetan Sarva
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # log_require
2
+
3
+ Log all calls to Kernel#require
4
+
5
+ ## Usage
6
+
7
+ This library should generally not be added to a `Gemfile`. Simply install it:
8
+
9
+ ```bash
10
+ $ gem install log_require
11
+ ```
12
+
13
+ Then use it like so:
14
+
15
+ ```text
16
+ $ ruby -rlog_require ./a.rb
17
+ require: ./b.rb >> ./a.rb:9
18
+ require: ./c.rb >> ./b.rb:2
19
+ require: openssl >> ./c.rb:2
20
+ require: openssl.so >> ruby-2.1.3/lib/ruby/2.1.0/openssl.rb:17
21
+ require: digest.so >> ruby-2.1.3/lib/ruby/2.1.0/digest.rb:1
22
+ require: openssl/bn >> ruby-2.1.3/lib/ruby/2.1.0/openssl.rb:19
23
+ require: openssl/cipher >> ruby-2.1.3/lib/ruby/2.1.0/openssl.rb:20
24
+ require: openssl/config >> ruby-2.1.3/lib/ruby/2.1.0/openssl.rb:21
25
+ require: stringio >> ruby-2.1.3/lib/ruby/2.1.0/openssl/config.rb:13
26
+ require: openssl/digest >> ruby-2.1.3/lib/ruby/2.1.0/openssl.rb:22
27
+ require: openssl/x509 >> ruby-2.1.3/lib/ruby/2.1.0/openssl.rb:23
28
+ require: openssl/ssl >> ruby-2.1.3/lib/ruby/2.1.0/openssl.rb:24
29
+ require: openssl/buffering >> ruby-2.1.3/lib/ruby/2.1.0/openssl/ssl.rb:17
30
+ require: fcntl >> ruby-2.1.3/lib/ruby/2.1.0/openssl/ssl.rb:18
31
+ require: ./d.rb >> ./a.rb:10
32
+ require: ./e.rb >> ./d.rb:2
33
+ require: ./f.rb >> ./e.rb:2
34
+ require: ./g.rb >> ./d.rb:3
35
+ ```
36
+
37
+ Output is written to STDERR by default.
38
+
39
+ The following environment variables can also be used to control the output:
40
+
41
+ * LOG_REQUIRE="filename" -- write to file instead of STDERR
42
+ * LOG_REQUIRE_GRAPH=1 -- display tree output
43
+
44
+ ## Contributing to log_require
45
+
46
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
47
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
48
+ * Fork the project.
49
+ * Start a feature/bugfix branch.
50
+ * Commit and push until you are happy with your contribution.
51
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
52
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
53
+
54
+ ## Copyright
55
+
56
+ Copyright (c) 2014 Chetan Sarva. See LICENSE.txt for
57
+ further details.
58
+
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "log_require"
18
+ gem.homepage = "http://github.com/chetan/log_require"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Log all calls to Kernel#require}
21
+ gem.description = %Q{Small utility to help track down that stray library}
22
+ gem.email = "chetan@pixelcop.net"
23
+ gem.authors = ["Chetan Sarva"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'yard'
29
+ YARD::Rake::YardocTask.new
30
+
31
+ task :default => :build
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,24 @@
1
+
2
+ module LogRequire
3
+ module Flat
4
+
5
+ # Log the `require` call to STDERR or, optionally, a file
6
+ def log_require(name)
7
+ # cleanup the caller name (only interested in path relative to gem or lib)
8
+ c, l = LogRequire.clean_caller(caller.first)
9
+
10
+ if LogRequire.file? then
11
+ $log_require.puts "#{name},#{c},#{l}"
12
+
13
+ else
14
+ pad = 110-name.length
15
+ pad = pad > 0 ? pad : 1
16
+ pad = (" " * pad)
17
+ STDERR.puts "require: #{name}#{pad}>> #{c}:#{l}"
18
+ end
19
+
20
+ return require_without_log(name)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,40 @@
1
+
2
+ module LogRequire
3
+ module Graph
4
+
5
+ def log_require(name)
6
+ # cleanup the caller name (only interested in path relative to gem or lib)
7
+ stack = caller
8
+ c, l = LogRequire.clean_caller(stack.first)
9
+
10
+ # clean up the require stack
11
+ while !LogRequire.find_caller(stack, $log_require_stack.last) do
12
+ $log_require_stack.pop
13
+ end
14
+
15
+ # cleanup the frame pointer
16
+ while !LogRequire.find_caller(stack, $log_require_frame.caller) do
17
+ $log_require_frame = $log_require_frame.parent
18
+ end
19
+
20
+ while !$log_require_frame.root?() &&
21
+ ($log_require_frame.caller == $log_require_frame.parent.caller || $log_require_frame.caller == c) do
22
+
23
+ $log_require_frame = $log_require_frame.parent
24
+ end
25
+
26
+ # add on to the stack
27
+ if ! $log_require_stack.include?(c) then
28
+ $log_require_stack << c
29
+ end
30
+
31
+ # log the node
32
+ new_node = $log_require_frame.add_child(c, name)
33
+ $log_require_frame = new_node
34
+
35
+ # dot he actual require
36
+ new_node.result = require_without_log(name)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,63 @@
1
+
2
+ module LogRequire
3
+ class Node
4
+
5
+ attr_reader :parent, :caller, :name, :children
6
+ attr_accessor :result
7
+
8
+ def initialize(parent, caller, name, dupe_caller=false)
9
+ @parent = parent
10
+ @caller = caller
11
+ @name = name
12
+ @children = []
13
+ @dupe_caller = dupe_caller
14
+ @result = false
15
+ end
16
+
17
+ def self.root
18
+ @root ||= new(nil, nil, :root)
19
+ end
20
+
21
+ def parent
22
+ if root? then
23
+ self
24
+ else
25
+ @parent
26
+ end
27
+ end
28
+
29
+ def root?
30
+ @parent.nil? && @name == :root
31
+ end
32
+
33
+ def add_child(caller, name)
34
+ dupe_caller = (!@children.empty? and @children.last.caller == caller)
35
+ @children << (node = Node.new(self, caller, name, dupe_caller))
36
+ node
37
+ end
38
+
39
+ def print_children(io, indent=1)
40
+ @children.each do |child|
41
+ io.puts child.to_graph_s(indent)
42
+ child.print_children(io, indent+2)
43
+ end
44
+ end
45
+
46
+ def to_graph_s(indent=1)
47
+ if root? then
48
+ "--+ root"
49
+ else
50
+ s = ""
51
+ s += "#{'| '*indent}|--+ #{@caller}\n" if !@dupe_caller
52
+ s += "#{'| '*(indent+1)}|--" + (@children.empty?() ? "=" : "+") + " #{@name}" +
53
+ (@result ? "" : " (#{@result})")
54
+ s
55
+ end
56
+ end
57
+
58
+ def to_s
59
+ "#{@caller} -> #{@name} (#{@result})"
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,70 @@
1
+
2
+ require "log_require/flat"
3
+ require "log_require/graph"
4
+ require "log_require/node"
5
+
6
+ module LogRequire
7
+
8
+ def self.graph?
9
+ !ENV["LOG_REQUIRE_GRAPH"].nil?
10
+ end
11
+
12
+ def self.file?
13
+ !ENV["LOG_REQUIRE"].nil?
14
+ end
15
+
16
+ def self.setup
17
+ io = if file? then
18
+ File.open(ENV["LOG_REQUIRE"], 'w')
19
+ else
20
+ STDERR
21
+ end
22
+
23
+ if graph? then
24
+ $log_require_stack = []
25
+ $log_require_frame = Node.root
26
+ Kernel.include(LogRequire::Graph)
27
+ at_exit do
28
+ io.puts
29
+ io.puts LogRequire::Node.root.to_graph_s()
30
+ LogRequire::Node.root.print_children(io)
31
+ end
32
+
33
+ else
34
+ $log_require = io
35
+ if file? then
36
+ io.puts "require name,caller,line number"
37
+ end
38
+ Kernel.include(LogRequire::Flat)
39
+ end
40
+ end
41
+
42
+ def self.clean_caller(c)
43
+ if c =~ %r{ruby-[\d.]+/gems/(.*):(\d+):in `.*$} ||
44
+ c =~ %r{(ruby-[\d.]+/lib/ruby/[\d.]+/.*):(\d+):in `.*$} ||
45
+ c =~ %r{(ruby/site_ruby/[\d.]+/.*):(\d+):in `.*$} ||
46
+ c =~ %r{^(.*?):(\d+):in `.*$} then
47
+
48
+ return [$1, $2]
49
+ end
50
+ end
51
+
52
+ def self.find_caller(arr, c)
53
+ arr.each do |s|
54
+ if s =~ /#{c}:\d+:in/ then
55
+ return true
56
+ end
57
+ end
58
+ false
59
+ end
60
+ end
61
+
62
+ module Kernel
63
+
64
+ if !method_defined?(:log_require) then
65
+ LogRequire.setup
66
+ alias_method :require_without_log, :require
67
+ alias_method :require, :log_require
68
+ end
69
+
70
+ end
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: log_require 0.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "log_require"
9
+ s.version = "0.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Chetan Sarva"]
14
+ s.date = "2014-10-30"
15
+ s.description = "Small utility to help track down that stray library"
16
+ s.email = "chetan@pixelcop.net"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/log_require.rb",
30
+ "lib/log_require/flat.rb",
31
+ "lib/log_require/graph.rb",
32
+ "lib/log_require/node.rb",
33
+ "log_require.gemspec",
34
+ "test/a.rb",
35
+ "test/b.rb",
36
+ "test/c.rb",
37
+ "test/d.rb",
38
+ "test/e.rb",
39
+ "test/f.rb",
40
+ "test/g.rb"
41
+ ]
42
+ s.homepage = "http://github.com/chetan/log_require"
43
+ s.licenses = ["MIT"]
44
+ s.rubygems_version = "2.4.2"
45
+ s.summary = "Log all calls to Kernel#require"
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 4
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<yard>, ["~> 0.7"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
54
+ else
55
+ s.add_dependency(%q<yard>, ["~> 0.7"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<yard>, ["~> 0.7"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
63
+ end
64
+ end
65
+
data/test/a.rb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # expected output:
4
+ #
5
+ # a -> b -> c -> openssl
6
+ # d -> e -> f
7
+ # -> g
8
+
9
+ require "./b.rb"
10
+ require "./d.rb"
11
+
data/test/b.rb ADDED
@@ -0,0 +1,2 @@
1
+
2
+ require "./c.rb"
data/test/c.rb ADDED
@@ -0,0 +1,2 @@
1
+
2
+ require "openssl"
data/test/d.rb ADDED
@@ -0,0 +1,3 @@
1
+
2
+ require "./e.rb"
3
+ require "./g.rb"
data/test/e.rb ADDED
@@ -0,0 +1,2 @@
1
+
2
+ require "./f.rb"
data/test/f.rb ADDED
File without changes
data/test/g.rb ADDED
File without changes
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: log_require
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chetan Sarva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jeweler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ description: Small utility to help track down that stray library
56
+ email: chetan@pixelcop.net
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files:
60
+ - LICENSE.txt
61
+ - README.md
62
+ files:
63
+ - ".document"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - VERSION
70
+ - lib/log_require.rb
71
+ - lib/log_require/flat.rb
72
+ - lib/log_require/graph.rb
73
+ - lib/log_require/node.rb
74
+ - log_require.gemspec
75
+ - test/a.rb
76
+ - test/b.rb
77
+ - test/c.rb
78
+ - test/d.rb
79
+ - test/e.rb
80
+ - test/f.rb
81
+ - test/g.rb
82
+ homepage: http://github.com/chetan/log_require
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.4.2
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Log all calls to Kernel#require
106
+ test_files: []