objenealogist 0.1.0 → 0.1.1

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: ca90d0b5901aa3b2d3d517d772c715b926545530421ea695646a80f4c10e432c
4
- data.tar.gz: 7f4f3f5a7aa8b5b1f24855e7b8fa68c258dbbc42686ff29ddc5767105d35782d
3
+ metadata.gz: 951cc96c6057b240c86ebcaba995b6635945e80a6a124bdbf6b0aadeb44832fa
4
+ data.tar.gz: c4401fde554422a401cbd2f28c64748f2453c06a120585914fa6fc895add4dad
5
5
  SHA512:
6
- metadata.gz: e406e9f86b6708851d5d56a2340001ec1d6574a8f36481bf1b388103f14712d24f38886d12529860d3b5f84b7673621b78d945f8a93a10d3cd24285e9673c586
7
- data.tar.gz: 9718d6c0482ee0e89799c75afb6d86a6e4b90824cae2ff09033da119e0dae326db491b4d9c5cf2fa6cce0620403453302c430c4a6cc60b6cfd92f5ebdfa0231e
6
+ metadata.gz: 596794eddd578b8f476b4eb18a173d2da6b12a6db44cde8feb03fc55468811ac99b0c96b6503ebc0b91f7d57e7792ed5223f43afefead7a9370970f8b708d53b
7
+ data.tar.gz: ba3ee209ea35ad5644f0ec2ba0591b8ecd54a04cea0daab6383e5b1ab56218249bf074500f226c417fbe150f0708403213f3573cb248a68eac9fdf7cb0345901
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Objenealogist
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/objenealogist.rb CHANGED
@@ -36,30 +36,35 @@ class Objenealogist
36
36
  locations = location_map[clazz.to_s.to_sym]
37
37
 
38
38
  result << "#{indent}C #{clazz}#{format_locations(locations, show_locations:, target: clazz.to_s)}" if indent == ""
39
- if locations && locations[:methods] && show_methods
40
- locations[:methods].sort do |a, b|
41
- a[2] == b[2] ? a[0] <=> b[0] : a[2] <=> b[2]
42
- end.each_with_index do |method, index|
43
- m, path, line = method
44
- mark = locations[:methods].size - 1 == index ? "└" : "├"
45
- result << "#{indent}│ #{mark} #{m}#{format_locations("#{path}:#{line}", show_locations:, target: clazz.to_s)}"
39
+ if show_methods
40
+ methods = class << clazz; public_instance_methods(false).map { |m| instance_method(m) }; end
41
+ methods += clazz.public_instance_methods(false).map do |m|
42
+ clazz.instance_method(m)
46
43
  end
47
- result << "#{indent}│"
44
+ methods.compact.sort { |a, b| a.name <=> b.name }.each_with_index do |method, index|
45
+ path, line = method.source_location
46
+ mark = methods.size - 1 == index ? "└" : "├"
47
+ result << "#{indent}│ #{mark} #{method.name}#{format_locations("#{path}:#{line}", show_locations:,
48
+ target: clazz.to_s)}"
49
+ end
50
+ result << "#{indent}│" if methods.any?
48
51
  end
49
52
 
50
53
  (clazz.included_modules - (clazz.superclass&.included_modules || [])).each do |mod|
51
54
  locations = location_map[mod.to_s.to_sym]
52
55
  result << "#{indent}├── M #{mod}#{format_locations(locations, show_locations:, target: mod.to_s)}"
53
- if locations && locations[:methods] && show_methods # rubocop:disable Style/Next
54
- locations[:methods].sort do |a, b|
55
- a[2] == b[2] ? a[0] <=> b[0] : a[2] <=> b[2]
56
- end.each_with_index do |method, index|
57
- m, path, line = method
58
- mark = locations[:methods].size - 1 == index ? "└" : "├"
59
- result << "#{indent}| #{mark} #{m}#{format_locations("#{path}:#{line}", show_locations:,
60
- target: mod.to_s)}"
56
+ if show_methods && mod != ::Kernel # rubocop:disable Style/Next
57
+ methods = class << mod; public_instance_methods(false).map { |m| instance_method(m) }; end
58
+ methods += mod.public_instance_methods(false).map do |m|
59
+ clazz.instance_method(m)
60
+ end
61
+ methods.compact.sort { |a, b| a.name <=> b.name }.each_with_index do |method, index|
62
+ path, line = method.source_location
63
+ mark = methods.size - 1 == index ? "└" : "├"
64
+ result << "#{indent}│ #{mark} #{method.name}#{format_locations("#{path}:#{line}", show_locations:,
65
+ target: mod.to_s)}"
61
66
  end
62
- result << "#{indent}|"
67
+ result << "#{indent}" if methods.any?
63
68
  end
64
69
  end
65
70
 
@@ -67,7 +72,11 @@ class Objenealogist
67
72
  locations = location_map[clazz.superclass.to_s.to_sym]
68
73
  result << "#{indent}└── C #{clazz.superclass}#{format_locations(locations, show_locations:,
69
74
  target: clazz.superclass.to_s)}"
70
- process_one(clazz.superclass, result, location_map, " #{indent}", show_methods:, show_locations:)
75
+ if clazz.superclass != ::BasicObject
76
+ process_one(clazz.superclass, result, location_map, " #{indent}", show_methods:, show_locations:)
77
+ else
78
+ result
79
+ end
71
80
  else
72
81
  result
73
82
  end
@@ -78,7 +87,7 @@ class Objenealogist
78
87
  return "" if show_locations.is_a?(Regexp) && show_locations !~ target
79
88
 
80
89
  if locations.is_a?(String)
81
- if locations != ":0" && show_locations
90
+ if locations != ":" && show_locations
82
91
  " (location: #{locations})"
83
92
  else
84
93
  ""
@@ -111,22 +120,9 @@ class Objenealogist
111
120
  (location_map[name] ||= { name: name, locations: [], methods: [] })[:locations] << [path, def_location]
112
121
  end
113
122
  end
114
- source_locations.uniq(&:join).each do |m, method_path, line|
115
- locations = location_map.values.find do |location|
116
- location[:locations].any? do |source_path, loc|
117
- method_path == source_path && loc.start_line <= line && line <= loc.end_line
118
- end
119
- end
120
- if locations
121
- locations[:methods] << [m, method_path, line]
122
- else
123
- location_map[clazz.to_s.to_sym]&.[](:methods)&.<< [m, nil, 0]
124
- end
125
- end
126
123
  # {M1:
127
124
  # {name: :M1,
128
- # locations: [["objenealogist.rb", (122,0)-(124,3)]],
129
- # methods: [[:m1, "objenealogist.rb", 123]]}}
125
+ # locations: [["objenealogist.rb", (122,0)-(124,3)]]}
130
126
  location_map
131
127
  end
132
128
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: objenealogist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koji NAKAMURA