mmmm 0.1.3 → 0.1.4

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: 1243a0d9d8c1ee44508e533fd277d74187d91d61
4
- data.tar.gz: 53a9d2c38916e6bbac2d01725c79bc67f1b790d7
3
+ metadata.gz: a9f1cf1b165a5b5c70a800ee3d5fc641552b3ab4
4
+ data.tar.gz: 39e1d73d93248f5bf5cb41fbc7d00d81990eec6a
5
5
  SHA512:
6
- metadata.gz: 6e481f68f7c35f6ada225962c184dc3dfdc7097d810fb460b6caef0c23bf742dddcd7730588d5b24b47aa225e5a56b8bde826f6088804ac82b387514dba69896
7
- data.tar.gz: 7d1c1da02a39e89c2667fb2aceefb6817462fde6c573bfd0a79ba846a40514eb5e135387437c15d8c8ef3d582b24931fe2d905ab8cbed7fd353806de9f918c18
6
+ metadata.gz: b33542499bb7e20bc5f4cd1d40a04c475f0a03561dd55f02b382fb2075a5c5e32f16497e9e27516668b479bbe3fdebd70b111885c20158a31459a8ac07c48fc1
7
+ data.tar.gz: e9970ad0598a27573b78fed9cb464134ec8a091fcbcd1be0638c4194734f96101e60ea18929305d917d640f1caf8d4818a0f983a171e0cdbb24a52ec11910dc5
@@ -11,8 +11,7 @@ module Mmmm
11
11
  def helper name
12
12
  if Mmmm::Top.respond_to? name or
13
13
  Mmmm::Top.private_methods.include? name
14
- raise NameError,"#{name} is already defined. Please use Mmmm.helper(:another_name)"
15
- return
14
+ raise NameError, "#{name} is already defined. Please use Mmmm.helper(:another_name)"
16
15
  end
17
16
  define_helper_method name
18
17
  end
@@ -7,8 +7,8 @@ module Mmmm
7
7
 
8
8
  def inspect
9
9
  @locs_in_all_ancs.
10
- map{|file, line| [file.cyan, line].join(' ')}.
11
- join("\n")
10
+ map{ |file, line| [file.cyan, line].join(' ') }.
11
+ join("\n")
12
12
  end
13
13
 
14
14
  private
@@ -24,7 +24,7 @@ module Mmmm
24
24
  loc = instance_method_location method_name, class_or_module
25
25
  locs << loc unless loc.nil?
26
26
  end.
27
- uniq
27
+ uniq
28
28
  end
29
29
 
30
30
  def instance_method_location method_name, mod
@@ -3,49 +3,60 @@ module Mmmm
3
3
 
4
4
  class FileLineMethod
5
5
  attr_reader :file, :line, :method
6
- def initialize src_loc, m
6
+ def initialize src_loc, m, inherited
7
7
  @file = src_loc[0]
8
8
  @line = src_loc[1]
9
9
  @method = m
10
+ @inherited = inherited
11
+ end
12
+
13
+ def inherited?
14
+ @inherited
10
15
  end
11
16
  end
12
17
 
13
18
  def initialize obj
14
- file = nil
15
- flm_arr = file_line_method_arr(obj)
16
- @group_by_file = group_by_file(flm_arr)
19
+ @obj = obj
17
20
  end
18
21
 
19
22
  def inspect
20
- @group_by_file.
21
- map {|file, flms| "#{file.cyan}\n#{lm_in_string(flms)}" }.
22
- join("\n")
23
+ group_by_inherited_and_file.
24
+ map { |inh_file, flms| "#{inh_file[1].cyan} #{inh_file[0]}\n#{lm_in_string(flms)}" }.
25
+ join("\n")
23
26
  end
24
27
 
25
28
  private
26
29
 
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
30
+ def file_line_method_arr
31
+ @obj.methods.each_with_object([]) do |m, rs|
32
+ file_line = @obj.method(m).source_location
33
+ rs << FileLineMethod.new(file_line, m, inherited?(m)) if file_line
34
34
  end
35
35
  end
36
36
 
37
- def group_by_file flm_arr
38
- grouped = flm_arr.
39
- group_by{|flm| flm.file}.
40
- sort_by{|file, flm| file}
37
+ def inherited? method
38
+ not open_class_defined_methods.include? method
39
+ end
40
+
41
+ def open_class_defined_methods
42
+ @ocdm ||= [:singleton_class, :class].
43
+ map{ |klass| @obj.send(klass).instance_methods(false) }.
44
+ flatten.
45
+ uniq
46
+ end
47
+
48
+ def group_by_inherited_and_file
49
+ grouped = file_line_method_arr.
50
+ group_by{ |flm| [flm.inherited?.to_s, flm.file] }.
51
+ sort_by{ |inh_f, _| inh_f }
41
52
 
42
53
  Hash[grouped]
43
54
  end
44
55
 
45
56
  def lm_in_string flms
46
57
  flms.
47
- map {|flm| "#{format('%5d', flm.line)} #{flm.method}" }.
48
- join("\n")
58
+ map {|flm| "#{format('%5d', flm.line)} #{flm.method}" }.
59
+ join("\n")
49
60
  end
50
61
  end
51
62
  end
@@ -1,3 +1,3 @@
1
1
  module Mmmm
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmmm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-25 00:00:00.000000000 Z
11
+ date: 2016-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  requirements: []
98
98
  rubyforge_project:
99
- rubygems_version: 2.4.8
99
+ rubygems_version: 2.6.7
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: find (all) method source location