where_is 0.3.0 → 0.3.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
  SHA1:
3
- metadata.gz: b6c7084127b003a146f929e32f5c7682be7adc42
4
- data.tar.gz: e0e7c87c2bdaf475baa3d3b0d4d35e2d5a8efa80
3
+ metadata.gz: 081429ac13b2f3e5ff923da95306900535c0ec39
4
+ data.tar.gz: 08b00b6d0696e13ffcf09be13fd68ace84aa350d
5
5
  SHA512:
6
- metadata.gz: f07a78076b84383157fdbd7246f5900bad72c9c8768d7676743a4cf180c72194765e8653bec37651b17d720c18b4f49806382a62a32ae94b436355796878fc6f
7
- data.tar.gz: 848a7dce9d1b383b8192fa31369748402527cb3dcc0c5aef169bb6515904b051e567066eed5e5503db17087b8c77a47cb70fe36c28a7709d21c421e07325138e
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
- # => ["/Users/david/.rvm/gems/ruby-2.3.1/gems/where_is-0.2.0/lib/where_is.rb", 5]
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
- # => ["/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/inspector.rb", 24]
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
- # => [["/Users/david/.rvm/gems/ruby-2.3.1/gems/where_is-0.2.0/lib/where_is.rb", 5]]
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
- # ["/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/inspector.rb", 24],
41
- # ["/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/workspace.rb", 112],
42
- # ["(eval)", 2],
43
- # ["/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb", 350],
44
- # ["/Users/david/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/init.rb", 16]
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)
@@ -1,3 +1,3 @@
1
1
  module Where
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
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
- return method.to_s[/: (.*)>/, 1] if source_location.nil?
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
- { file: filename, line: line, path: "#{filename}:#{line}" }
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[0] }.to_a
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[1] }
98
+ lines = src_locs.map { |sl| sl[:line] }
99
99
  count = lines.size
100
100
  line = lines.min
101
- { file: file, count: count, line: line }
101
+ { count: count, data: build_location_hash(file, line) }
102
102
  end
103
103
 
104
- file_groups.sort_by! { |fc| fc[:count] }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: where_is
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Allie