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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 355b6e4fe1af02875a46c394cf82339e21fc3058
4
- data.tar.gz: 33f3f2e282de829772fcac530056a92d16db942d
3
+ metadata.gz: 1243a0d9d8c1ee44508e533fd277d74187d91d61
4
+ data.tar.gz: 53a9d2c38916e6bbac2d01725c79bc67f1b790d7
5
5
  SHA512:
6
- metadata.gz: e9322e14ef3a4ee3d95294a24413d9d593a9dcdd9e9ed217f095a93e70fdf2c2e8af8073f27cd41a2e6e7af31d7c66b7e7ad9bc901a4141480426b1797ec62e3
7
- data.tar.gz: aa794b129795b4c98a204e743adad8a734a3a26d3ea0b92ec3c29f2da5080423603ae93c850e1710115692849fc3039ab9ca99d7636db48797d0cef21f574875
6
+ metadata.gz: 6e481f68f7c35f6ada225962c184dc3dfdc7097d810fb460b6caef0c23bf742dddcd7730588d5b24b47aa225e5a56b8bde826f6088804ac82b387514dba69896
7
+ data.tar.gz: 7d1c1da02a39e89c2667fb2aceefb6817462fde6c573bfd0a79ba846a40514eb5e135387437c15d8c8ef3d582b24931fe2d905ab8cbed7fd353806de9f918c18
data/lib/mmmm/color.rb ADDED
@@ -0,0 +1,5 @@
1
+ class String
2
+ def cyan
3
+ "\e[36m#{self}\e[0m"
4
+ end
5
+ end
data/lib/mmmm/helper.rb CHANGED
@@ -3,7 +3,7 @@ Mmmm::Top = self
3
3
  module Mmmm
4
4
 
5
5
  Helper = Proc.new do |obj, method = nil|
6
- Mmmm[obj, method]
6
+ Mmmm.src obj, method
7
7
  end
8
8
 
9
9
  class << self
@@ -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
- class FileLineMethod
4
- attr_reader :file, :line, :method
5
- def initialize src_loc, m
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
@@ -1,3 +1,3 @@
1
1
  module Mmmm
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/mmmm.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "mmmm/version"
2
+ require "mmmm/color"
2
3
  require "mmmm/src_loc"
3
4
  require "mmmm/helper"
4
5
 
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.2
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.6.7
99
+ rubygems_version: 2.4.8
97
100
  signing_key:
98
101
  specification_version: 4
99
102
  summary: find (all) method source location