where_is 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -9
- data/lib/where_is/version.rb +1 -1
- data/lib/where_is.rb +14 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 081429ac13b2f3e5ff923da95306900535c0ec39
|
4
|
+
data.tar.gz: 08b00b6d0696e13ffcf09be13fd68ace84aa350d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 422ceefba0193373a6016311b0e504ca081d084c87d4e8ceb7e4e790615d725eb75da1de33c97e96fa3601df12fe954fa0241ec0a769c3b9dbbc1588580fd88d
|
7
|
+
data.tar.gz: e962135912c48d7f22b2bafc9215012e8bf56089b30254edfe3e656e8ebc1ccd8794ee349d3321a32167b2c5ca57cc766dde908d810462cd6d7c92c2517c4fb9
|
data/README.md
CHANGED
@@ -24,25 +24,28 @@ Or install it yourself as:
|
|
24
24
|
# Where.is takes a class and an optional method
|
25
25
|
|
26
26
|
Where.is(Where, :is)
|
27
|
-
# =>
|
27
|
+
# => {:file=>"/Users/david/repos/daveallie/where_is/lib/where_is.rb", :line=>5, :path=>"/Users/david/repos/daveallie/where_is/lib/where_is.rb:5"}
|
28
28
|
|
29
29
|
Where.is(IRB)
|
30
|
-
# =>
|
30
|
+
# => {:file=>"/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/inspector.rb", :line=>24, :path=>"/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/inspector.rb:24"}
|
31
|
+
|
32
|
+
Where.is(String, :empty?) # This method is defined in C
|
33
|
+
# => {:file=>"String#empty?", :line=>nil, :path=>"String#empty?:"}
|
31
34
|
|
32
35
|
|
33
36
|
# Where.are takes a class and an optional method and will return all definitions
|
34
37
|
# of the method/class
|
35
38
|
Where.are(Where, :is)
|
36
|
-
# => [
|
39
|
+
# => [{:file=>"/Users/david/repos/daveallie/where_is/lib/where_is.rb", :line=>5, :path=>"/Users/david/repos/daveallie/where_is/lib/where_is.rb:5"}]
|
37
40
|
|
38
41
|
Where.are(IRB)
|
39
42
|
# => [
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#]
|
43
|
+
# {:file=>"/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/inspector.rb", :line=>24, :path=>"/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/inspector.rb:24"},
|
44
|
+
# {:file=>"/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/workspace.rb", :line=>112, :path=>"/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/workspace.rb:112"},
|
45
|
+
# {:file=>"(eval)", :line=>2, :path=>"(eval):2"},
|
46
|
+
# {:file=>"/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb", :line=>350, :path=>"/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:350"},
|
47
|
+
# {:file=>"/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/init.rb", :line=>16, :path=>"/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/init.rb:16"}
|
48
|
+
# ]
|
46
49
|
|
47
50
|
|
48
51
|
Where.is(String, :unknown_method)
|
data/lib/where_is/version.rb
CHANGED
data/lib/where_is.rb
CHANGED
@@ -81,31 +81,31 @@ module Where
|
|
81
81
|
|
82
82
|
def source_location(method)
|
83
83
|
source_location = method.source_location
|
84
|
-
|
84
|
+
source_location = [method.to_s[/: (.*)>/, 1]] if source_location.nil?
|
85
85
|
|
86
86
|
# source_location is a 2 element array
|
87
87
|
# [filename, line_number]
|
88
88
|
# some terminals (eg. iterm) will jump to the file if you cmd+click it
|
89
89
|
# but they can jump to the specific line if you concat file & line number
|
90
90
|
filename, line = source_location
|
91
|
-
|
91
|
+
build_location_hash(filename, line)
|
92
92
|
end
|
93
93
|
|
94
94
|
def group_and_combine_source_locations(source_locations)
|
95
|
-
file_groups = source_locations.group_by { |src_loc| src_loc[
|
95
|
+
file_groups = source_locations.group_by { |src_loc| src_loc[:file] }.to_a
|
96
96
|
|
97
97
|
file_groups.map! do |file, src_locs|
|
98
|
-
lines = src_locs.map { |sl| sl[
|
98
|
+
lines = src_locs.map { |sl| sl[:line] }
|
99
99
|
count = lines.size
|
100
100
|
line = lines.min
|
101
|
-
{
|
101
|
+
{ count: count, data: build_location_hash(file, line) }
|
102
102
|
end
|
103
103
|
|
104
|
-
file_groups.sort_by
|
105
|
-
file_groups.map { |fc| [fc[:file], fc[:line]] }
|
104
|
+
file_groups.sort_by { |fc| fc[:count] }.map { |fc| fc[:data] }
|
106
105
|
end
|
107
106
|
|
108
107
|
def are_via_extractor(extractor, klass, method_name)
|
108
|
+
klass = klass.class unless [Class, Module].include?(klass.class)
|
109
109
|
klass.ancestors.map do |ancestor|
|
110
110
|
begin
|
111
111
|
source_location(ancestor.send(extractor, method_name))
|
@@ -116,11 +116,15 @@ module Where
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def defined_methods(klass)
|
119
|
-
methods = klass.methods(false)
|
120
|
-
.map { |m| klass.method(m) }
|
119
|
+
methods = klass.methods(false).map { |m| klass.method(m) }
|
121
120
|
methods += klass.instance_methods(false)
|
122
121
|
.map { |m| klass.instance_method(m) }
|
123
|
-
methods.map(&:source_location).compact
|
122
|
+
source_locations = methods.map(&:source_location).compact
|
123
|
+
source_locations.map { |(file, line)| build_location_hash(file, line) }
|
124
|
+
end
|
125
|
+
|
126
|
+
def build_location_hash(file, line)
|
127
|
+
{ file: file, line: line, path: "#{file}:#{line}" }
|
124
128
|
end
|
125
129
|
end
|
126
130
|
end
|