mmmm 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mmmm/color.rb +5 -0
- data/lib/mmmm/helper.rb +1 -1
- data/lib/mmmm/object_method.rb +36 -0
- data/lib/mmmm/object_methods.rb +51 -0
- data/lib/mmmm/src_loc.rb +6 -72
- data/lib/mmmm/version.rb +1 -1
- data/lib/mmmm.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1243a0d9d8c1ee44508e533fd277d74187d91d61
|
4
|
+
data.tar.gz: 53a9d2c38916e6bbac2d01725c79bc67f1b790d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e481f68f7c35f6ada225962c184dc3dfdc7097d810fb460b6caef0c23bf742dddcd7730588d5b24b47aa225e5a56b8bde826f6088804ac82b387514dba69896
|
7
|
+
data.tar.gz: 7d1c1da02a39e89c2667fb2aceefb6817462fde6c573bfd0a79ba846a40514eb5e135387437c15d8c8ef3d582b24931fe2d905ab8cbed7fd353806de9f918c18
|
data/lib/mmmm/color.rb
ADDED
data/lib/mmmm/helper.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Mmmm
|
2
|
+
class ObjectMethod
|
3
|
+
def initialize obj, method_name
|
4
|
+
ancs = all_ancestors(obj)
|
5
|
+
@locs_in_all_ancs = instance_method_locations(method_name, ancs)
|
6
|
+
end
|
7
|
+
|
8
|
+
def inspect
|
9
|
+
@locs_in_all_ancs.
|
10
|
+
map{|file, line| [file.cyan, line].join(' ')}.
|
11
|
+
join("\n")
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def all_ancestors obj
|
17
|
+
obj.
|
18
|
+
singleton_class.
|
19
|
+
ancestors
|
20
|
+
end
|
21
|
+
|
22
|
+
def instance_method_locations method_name, mods
|
23
|
+
mods.each_with_object([]) do |class_or_module, locs|
|
24
|
+
loc = instance_method_location method_name, class_or_module
|
25
|
+
locs << loc unless loc.nil?
|
26
|
+
end.
|
27
|
+
uniq
|
28
|
+
end
|
29
|
+
|
30
|
+
def instance_method_location method_name, mod
|
31
|
+
mod.instance_method(method_name).source_location
|
32
|
+
rescue NameError => e
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Mmmm
|
2
|
+
class ObjectMethods
|
3
|
+
|
4
|
+
class FileLineMethod
|
5
|
+
attr_reader :file, :line, :method
|
6
|
+
def initialize src_loc, m
|
7
|
+
@file = src_loc[0]
|
8
|
+
@line = src_loc[1]
|
9
|
+
@method = m
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize obj
|
14
|
+
file = nil
|
15
|
+
flm_arr = file_line_method_arr(obj)
|
16
|
+
@group_by_file = group_by_file(flm_arr)
|
17
|
+
end
|
18
|
+
|
19
|
+
def inspect
|
20
|
+
@group_by_file.
|
21
|
+
map {|file, flms| "#{file.cyan}\n#{lm_in_string(flms)}" }.
|
22
|
+
join("\n")
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def file_line_method_arr obj
|
28
|
+
obj.methods.reduce([]) do |rs, m|
|
29
|
+
file_line = obj.method(m).source_location
|
30
|
+
if file_line
|
31
|
+
rs << FileLineMethod.new(file_line, m)
|
32
|
+
end
|
33
|
+
rs
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def group_by_file flm_arr
|
38
|
+
grouped = flm_arr.
|
39
|
+
group_by{|flm| flm.file}.
|
40
|
+
sort_by{|file, flm| file}
|
41
|
+
|
42
|
+
Hash[grouped]
|
43
|
+
end
|
44
|
+
|
45
|
+
def lm_in_string flms
|
46
|
+
flms.
|
47
|
+
map {|flm| "#{format('%5d', flm.line)} #{flm.method}" }.
|
48
|
+
join("\n")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/mmmm/src_loc.rb
CHANGED
@@ -1,77 +1,11 @@
|
|
1
|
+
require 'mmmm/object_method'
|
2
|
+
require 'mmmm/object_methods'
|
3
|
+
|
1
4
|
module Mmmm
|
2
5
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@file = src_loc[0]
|
7
|
-
@line = src_loc[1]
|
8
|
-
@method = m
|
9
|
-
end
|
6
|
+
def self.src obj, method = nil
|
7
|
+
return ObjectMethod.new(obj, method) if method
|
8
|
+
ObjectMethods.new obj
|
10
9
|
end
|
11
10
|
|
12
|
-
class << self
|
13
|
-
|
14
|
-
def [](obj, method = nil)
|
15
|
-
return src_loc obj, method if method
|
16
|
-
all_src_loc obj
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def src_loc obj, method_name
|
23
|
-
ancs = all_ancestors(obj)
|
24
|
-
instance_method_locations(method_name, ancs).
|
25
|
-
each do |file, line|
|
26
|
-
puts [cyan(file), line].join ' '
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def all_ancestors obj
|
31
|
-
obj.
|
32
|
-
singleton_class.
|
33
|
-
ancestors
|
34
|
-
end
|
35
|
-
|
36
|
-
def instance_method_locations method_name, mods
|
37
|
-
mods.each_with_object([]) do |class_or_module, locs|
|
38
|
-
loc = instance_method_location method_name, class_or_module
|
39
|
-
locs << loc unless loc.nil?
|
40
|
-
end.
|
41
|
-
uniq
|
42
|
-
end
|
43
|
-
|
44
|
-
def instance_method_location method_name, mod
|
45
|
-
mod.instance_method(method_name).source_location
|
46
|
-
rescue NameError => e
|
47
|
-
nil
|
48
|
-
end
|
49
|
-
|
50
|
-
def all_src_loc obj
|
51
|
-
file = nil
|
52
|
-
file_line_method_arr(obj).sort_by do |flm|
|
53
|
-
[flm.file, flm.line]
|
54
|
-
end.each do |flm|
|
55
|
-
unless file == flm.file
|
56
|
-
file = flm.file
|
57
|
-
puts cyan file
|
58
|
-
end
|
59
|
-
puts [format('%5d', flm.line), flm.method].join ' '
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def file_line_method_arr obj
|
64
|
-
obj.methods.reduce([]) do |rs, m|
|
65
|
-
file_line = obj.method(m).source_location
|
66
|
-
if file_line
|
67
|
-
rs << FileLineMethod.new(file_line, m)
|
68
|
-
end
|
69
|
-
rs
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def cyan str
|
74
|
-
"\e[36m#{str}\e[0m"
|
75
|
-
end
|
76
|
-
end
|
77
11
|
end
|
data/lib/mmmm/version.rb
CHANGED
data/lib/mmmm.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mmmm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken
|
@@ -69,7 +69,10 @@ files:
|
|
69
69
|
- bin/console
|
70
70
|
- bin/setup
|
71
71
|
- lib/mmmm.rb
|
72
|
+
- lib/mmmm/color.rb
|
72
73
|
- lib/mmmm/helper.rb
|
74
|
+
- lib/mmmm/object_method.rb
|
75
|
+
- lib/mmmm/object_methods.rb
|
73
76
|
- lib/mmmm/src_loc.rb
|
74
77
|
- lib/mmmm/version.rb
|
75
78
|
- mmmm.gemspec
|
@@ -93,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
96
|
version: '0'
|
94
97
|
requirements: []
|
95
98
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.4.8
|
97
100
|
signing_key:
|
98
101
|
specification_version: 4
|
99
102
|
summary: find (all) method source location
|