load_tracer 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: 54faee11fca635fb5444d731ba08da06967dd8b26f6164282ae8fe748149840a
4
- data.tar.gz: c759a241b21b3c04f34b83274a67abce0a6a3c3c56a6ec92df1c201848859872
3
+ metadata.gz: bdcf72ff4eb8378b4450689b64b9b6bf5a97a679baa47709414834ecb87f705b
4
+ data.tar.gz: 387db21e56a184a66f308b59b761641f3142702f29a3e47d3dbbdef65db5cf85
5
5
  SHA512:
6
- metadata.gz: 2c48aca3dbca0cafe40c9aedf1b97c37c9dd325b77fb6c1be41fa7804fb9625d46c8d375a97e1a7cc08ffd53c224ffc6eb994a76a3cfce52e41a0d11cdd09d34
7
- data.tar.gz: 2b980c8f85959c33b4fc98eb3a7717a1e25ab1af8062ab285633003ec745de0ce9fa4340f3d5b91954a947994426c635b2175e8b1494ed600b787f58999acbf1
6
+ metadata.gz: c3458986d97707e5e4324095d16c51e1c157b437efca8664cdc0cd269dac08676494c8d420934dee9fb101dbdcce145c09d095afa17ea3504c1a35f058d44dcf
7
+ data.tar.gz: 73ebe3f5d161787a283bfe3e65f91d77a42841e386d303055ca1fb719723c4006639a80d90d27c64a366b53e29d3ab5a76b030adb087a1adba5bcde5094d8151
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- load_tracer (0.2.0)
4
+ load_tracer (0.3.0)
5
5
  binding_of_caller (~> 0.8.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -6,6 +6,12 @@ require `RUBY_VERSION` >= 2.7.0
6
6
 
7
7
  ## Installation
8
8
 
9
+ ```
10
+ gem install load_tracer
11
+ ```
12
+
13
+ ### build local
14
+
9
15
  clone this repository.
10
16
 
11
17
  ```
@@ -21,7 +27,7 @@ bundle exec rake build
21
27
  install gem.
22
28
 
23
29
  ```
24
- gem install pkg/load_tracer-0.1.0.gem
30
+ gem install pkg/load_tracer-0.3.0.gem
25
31
  ```
26
32
 
27
33
 
@@ -50,6 +56,8 @@ puts LoadTracer.trace(format: :dot) { require 'prime' }
50
56
  ruby example.rb | dot -Tpng -o example.png | open example.png
51
57
  ```
52
58
 
59
+ ![](images/example.png)
60
+
53
61
  ## License
54
62
 
55
63
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/exe/rutrace ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'load_tracer'
4
+ require 'optparse'
5
+
6
+ options = { format: :json }
7
+
8
+ opt_parse = OptionParser.new do |opt|
9
+ opt.banner = 'Usage: rutrace programfile'
10
+ opt.on('-f', '-f format', 'specify output format.') { |format| options[:format] = format.to_sym }
11
+
12
+ opt.parse!(ARGV)
13
+ end
14
+
15
+ if ARGV.first.nil?
16
+ puts opt_parse
17
+ else
18
+ path = File.expand_path(ARGV.first, Dir.pwd)
19
+
20
+ puts LoadTracer.trace(format: options[:format], exclude_files: ['rutrace']) { require_relative path }
21
+ end
Binary file
data/lib/load_tracer.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'binding_of_caller'
2
2
  require 'load_tracer/formatter/default'
3
3
  require 'load_tracer/formatter/dot'
4
+ require 'load_tracer/formatter/json'
4
5
  require 'load_tracer/version'
5
6
 
6
7
  module Kernel
@@ -42,43 +43,43 @@ class LoadTracer
42
43
 
43
44
  LOAD_METHODS = %i(require require_relative load autoload)
44
45
 
45
- def self.trace(format: nil)
46
- instance = new
46
+ def self.trace(format: nil, exclude_files: [])
47
+ instance = new(exclude_files: exclude_files)
47
48
  instance.tracer.enable { yield }
48
49
  instance.report(format: format)
49
50
  end
50
51
 
51
- def initialize
52
+ def initialize(exclude_files: [])
52
53
  @dependencies = Hash.new { |hash, key| hash[key] = [] }
53
54
  @reverse_dependencies = Hash.new { |hash, key| hash[key] = [] }
55
+ @exclude_files = exclude_files
54
56
  @not_found_features = []
55
57
  end
56
58
 
57
59
  def tracer
58
- TracePoint.new(:return) do |tp|
60
+ TracePoint.new(:call) do |tp|
59
61
  next unless LOAD_METHODS.include?(tp.method_id)
60
62
  next if tp.defined_class != ::Kernel
61
63
  next if tp.path != __FILE__
62
64
 
63
- case tp.event
64
- when :return
65
- bl = caller_locations[1]
66
- feature = get_feature(tp)
65
+ bl = caller_locations[1]
66
+ feature = get_feature(tp)
67
67
 
68
- if bl.absolute_path.nil?
69
- bl = find_caller_of_internal_library(feature)
70
- end
68
+ if bl.absolute_path.nil?
69
+ bl = find_caller_of_internal_library(feature)
70
+ end
71
71
 
72
- path = find_path(feature) || find_path(File.expand_path(feature, File.dirname(bl.path)))
72
+ next if @exclude_files.include?(File.basename(bl.absolute_path))
73
73
 
74
- if path.nil?
75
- @not_found_features << feature
76
- next
77
- end
74
+ path = find_path(feature) || find_path(File.expand_path(feature, File.dirname(bl.path)))
78
75
 
79
- @dependencies[bl.absolute_path] << path
80
- @reverse_dependencies[path] << bl.absolute_path
76
+ if path.nil?
77
+ @not_found_features << feature
78
+ next
81
79
  end
80
+
81
+ @dependencies[bl.absolute_path] << path
82
+ @reverse_dependencies[path] << bl.absolute_path
82
83
  end
83
84
  end
84
85
 
@@ -88,6 +89,11 @@ class LoadTracer
88
89
  DotFormatter.export(
89
90
  dependencies: @dependencies
90
91
  )
92
+ when :json
93
+ JsonFormatter.export(
94
+ dependencies: @dependencies,
95
+ reverse_dependencies: @reverse_dependencies
96
+ )
91
97
  else
92
98
  DefaultFormatter.export(
93
99
  dependencies: @dependencies,
@@ -0,0 +1,14 @@
1
+ require 'json'
2
+
3
+ class LoadTracer
4
+ class JsonFormatter
5
+ def self.export(dependencies:, reverse_dependencies:)
6
+ report = DefaultFormatter.export(
7
+ dependencies: dependencies,
8
+ reverse_dependencies: reverse_dependencies
9
+ )
10
+
11
+ report.map(&:to_h).to_json
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  class LoadTracer
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
data/load_tracer.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Shuichi Tamayose']
9
9
  spec.email = ['tmshuichi@gmail.com']
10
10
 
11
- spec.summary = %q{TBD}
12
- spec.description = %q{TBD}
11
+ spec.summary = %q{This gem can check the dependency files.}
12
+ spec.description = %q{This gem can check the dependency files.}
13
13
  spec.homepage = 'https://github.com/siman-man/load_tracer'
14
14
  spec.license = 'MIT'
15
15
  spec.required_ruby_version = '> 2.6.99'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: load_tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shuichi Tamayose
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-01 00:00:00.000000000 Z
11
+ date: 2019-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -66,10 +66,11 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.8.0
69
- description: TBD
69
+ description: This gem can check the dependency files.
70
70
  email:
71
71
  - tmshuichi@gmail.com
72
- executables: []
72
+ executables:
73
+ - rutrace
73
74
  extensions: []
74
75
  extra_rdoc_files: []
75
76
  files:
@@ -84,9 +85,12 @@ files:
84
85
  - Rakefile
85
86
  - bin/console
86
87
  - bin/setup
88
+ - exe/rutrace
89
+ - images/example.png
87
90
  - lib/load_tracer.rb
88
91
  - lib/load_tracer/formatter/default.rb
89
92
  - lib/load_tracer/formatter/dot.rb
93
+ - lib/load_tracer/formatter/json.rb
90
94
  - lib/load_tracer/formatter/templates/default.dot.erb
91
95
  - lib/load_tracer/version.rb
92
96
  - load_tracer.gemspec
@@ -112,5 +116,5 @@ requirements: []
112
116
  rubygems_version: 3.0.2
113
117
  signing_key:
114
118
  specification_version: 4
115
- summary: TBD
119
+ summary: This gem can check the dependency files.
116
120
  test_files: []