method_info 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
@@ -34,6 +34,8 @@ module MethodInfo
34
34
  @options = options
35
35
 
36
36
  @ancestors = []
37
+ @unattributed_methods = []
38
+
37
39
  if options[:singleton_methods]
38
40
  begin
39
41
  @ancestors << (class << object; self; end)
@@ -54,6 +56,9 @@ module MethodInfo
54
56
  if @ancestors.include?(ancestor)
55
57
  @ancestor_methods[ancestor] << method
56
58
  end
59
+ unless ancestor
60
+ @unattributed_methods << method
61
+ end
57
62
  end
58
63
 
59
64
  def to_a
@@ -91,6 +96,9 @@ module MethodInfo
91
96
  if @options[:include_names_of_excluded_ancestors] && ! @ancestor_filter.excluded.empty?
92
97
  s += "#{message_color}Excluded:#{reset_color} " + @ancestor_filter.excluded.join(', ') + "\n"
93
98
  end
99
+ if @options[:include_names_of_unattributed_methods] && ! @unattributed_methods.empty?
100
+ s += "#{message_color}Unattributed methods:#{reset_color} " + @unattributed_methods.join(', ') + "\n"
101
+ end
94
102
  s += reset_color
95
103
  s
96
104
  end
@@ -122,17 +130,25 @@ module MethodInfo
122
130
  # 37.method(:ceil).to_s => "#<Method: Fixnum(Integer)#ceil>"
123
131
  # 37.method(:prec).to_s => "#<Method: Fixnum(Precision)#prec>"
124
132
  # obj.method(:singleton_method).to_s => "#<Method: #<Object:0x5673b8>.singleton_method>"
125
- if method.to_s =~ /^#<Method: (.*)[#.]#{Regexp.escape(method_name)}>$/
126
- owner_string = $1
127
- # Maybe it is a top level class and we're done
128
- if owner_string =~ /\w+\((\w+)\)/
129
- # Module or subclass (like 'Fixnum(Integer)')
130
- owner_string = $1
131
- elsif owner_string.include?("#<Object:")
132
- # probably the eigen class
133
- owner_string = "#<Class:#{owner_string}>"
133
+ # For a nested module: "#<Method: Module1::ClassName(Module1::Module2::Module3)#method>"
134
+
135
+ build_ancestor_regexp_map
136
+ @ancestors.each do |ancestor|
137
+ return ancestor if method.to_s =~ @ancestor_regexp_map[ancestor]
138
+ end
139
+ nil
140
+ end
141
+
142
+ def build_ancestor_regexp_map
143
+ unless @ancestor_regexp_map
144
+ @ancestor_regexp_map = Hash.new
145
+ @ancestors.each do |ancestor|
146
+ ancestor_name = ancestor.to_s
147
+ if ancestor_name =~ /^#<Class:(.*)>$/
148
+ ancestor_name = $1
149
+ end
150
+ @ancestor_regexp_map[ancestor] = /#{Regexp.escape(ancestor_name)}[)#.]/
134
151
  end
135
- @ancestors.select { |a| a.to_s == owner_string }.first
136
152
  end
137
153
  end
138
154
  end
@@ -83,6 +83,36 @@ module MethodInfo
83
83
  ams = AncestorMethodStructure.new(obj, :singleton_methods => true)
84
84
  ams.send(:poor_mans_method_owner, obj.method(:foo), "foo").should == class << obj; self; end
85
85
  end
86
+
87
+ it "finds the owner if it is nested" do
88
+ module TestNestOne
89
+ module TestNestTwo
90
+ def nest
91
+ :nest
92
+ end
93
+ end
94
+ end
95
+
96
+ class TestNest
97
+ include TestNestOne::TestNestTwo
98
+ end
99
+ obj = TestNest.new
100
+
101
+ ams = AncestorMethodStructure.new(obj, {})
102
+ ams.send(:poor_mans_method_owner, obj.method(:nest), "nest").should == MethodInfo::TestNestOne::TestNestTwo
103
+ end
104
+
105
+ it "finds the owner if it is an anonymous module" do
106
+ anon = Module.new
107
+ anon.send(:define_method, :bla) { :bla }
108
+ class UsingAnonymous
109
+ end
110
+ UsingAnonymous.send(:include, anon)
111
+ obj = UsingAnonymous.new
112
+
113
+ ams = AncestorMethodStructure.new(obj, {})
114
+ ams.send(:poor_mans_method_owner, obj.method(:bla), "bla").should == anon
115
+ end
86
116
  end
87
117
  end
88
118
  end
@@ -113,8 +113,9 @@ module MethodInfo
113
113
  end
114
114
 
115
115
  it "provides access to it's default options" do
116
+ MethodInfo::OptionHandler.default_options = { :fruit => :apple }
116
117
  MethodInfo::OptionHandler.default_options[:foo] = :bar
117
- MethodInfo::OptionHandler.default_options.should == { :foo => :bar }
118
+ MethodInfo::OptionHandler.default_options.should == { :fruit => :apple, :foo => :bar }
118
119
  end
119
120
  end
120
121
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom ten Thij
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-22 00:00:00 +00:00
12
+ date: 2010-02-23 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency