spicycode-inspector 0.1.0 → 0.2.0

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.
Files changed (2) hide show
  1. data/lib/inspector.rb +25 -14
  2. metadata +2 -2
data/lib/inspector.rb CHANGED
@@ -4,9 +4,8 @@ require 'ruby2ruby'
4
4
 
5
5
  class Inspector
6
6
 
7
- def self._collect_events_for_method_call(settings = {}, &block)
8
- settings[:debug] ||= false
9
-
7
+ def self._collect_events_for_method_call(&block)
8
+
10
9
  events = []
11
10
 
12
11
  set_trace_func lambda { |event, file, line, id, binding, classname|
@@ -22,12 +21,15 @@ class Inspector
22
21
  events
23
22
  end
24
23
 
25
- def self._trace_the_method_call(settings={}, &block)
26
- events = _collect_events_for_method_call settings, &block
27
- events.reject! { |event| !%w{call c-call return}.include?(event[:event]) }
28
-
24
+ def self._trace_the_method_call(&block)
25
+ events = _collect_events_for_method_call &block
26
+
27
+ # events.reject! { |event| !%w{call c-call return}.include?(event[:event]) }
28
+ valid_event_types = ['call', 'c-call', 'return']
29
+
29
30
  events.each do |event|
30
-
31
+ next unless valid_event_types.include?(event[:event])
32
+
31
33
  case event[:classname].to_s
32
34
  when 'ActiveRecord::Base'
33
35
  return events[-3]
@@ -40,8 +42,8 @@ class Inspector
40
42
 
41
43
  # Original version from http://holgerkohnen.blogspot.com/
42
44
  # which { some_object.some_method() } => <file>:<line>:
43
- def self.where_is_this_defined(settings={}, &block)
44
- event = _trace_the_method_call(settings, &block)
45
+ def self.where_is_this_defined(&block)
46
+ event = _trace_the_method_call(&block)
45
47
 
46
48
  if event
47
49
  # TODO: If the file is (irb) or event[:event] is c-call note it differently in the output
@@ -51,9 +53,9 @@ class Inspector
51
53
  end
52
54
  end
53
55
 
54
- def self.how_is_this_defined(settings={}, &block)
56
+ def self.how_is_this_defined(&block)
55
57
  begin
56
- event = _trace_the_method_call(settings, &block)
58
+ event = _trace_the_method_call(&block)
57
59
 
58
60
  if event
59
61
  if event[:classname].to_s == 'ActiveRecord::Base'
@@ -64,14 +66,23 @@ class Inspector
64
66
  else
65
67
  "Unable to determine where the method was defined in order to get to it's source"
66
68
  end
67
-
69
+ rescue RuntimeError => rte
70
+ # Assuming class level method
71
+ return RubyToRuby.translate(event[:classname], "self.#{event[:id]}")
68
72
  rescue NoMethodError => nme
69
73
  if nme.message =~ /^undefined method \`(.*)\' for nil\:NilClass/
70
- return "Unable to get the souce for #{event[:classname]}.#{event[:id]} because it is a function defined in C"
74
+ return "Unable to get the source for #{event[:classname]}.#{event[:id]} because it is a function defined in C"
71
75
  end
72
76
  raise
73
77
  end
74
78
  end
79
+
80
+ def self.detector(&block)
81
+ where = where_is_this_defined(&block)
82
+ how = how_is_this_defined(&block)
83
+
84
+ "Sir, here are the details of your inquiry:\nThe method in question was found to be defined in:\n#{where}Also, it was found to look like the following on the inside:\n#{how}"
85
+ end
75
86
 
76
87
  end
77
88
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spicycode-inspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Humphries
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-13 00:00:00 -07:00
12
+ date: 2008-10-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15