method_info 0.1.9 → 0.1.10

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.9
1
+ 0.1.10
@@ -23,28 +23,13 @@ module MethodInfo
23
23
  # :suppress_slowness_warning Does not print out the warning about slowness on older ruby versions (default: false)
24
24
  # :match Shows only those methods that match this option. It's value can be either a string or a regexp (default: nil)
25
25
  def self.build(object, options)
26
- if VERSION < "1.8.7" && !options[:suppress_slowness_warning]
27
- STDERR.puts "You are using Ruby #{VERSION}, this may take a while. It will be faster for >=1.8.7."
26
+ # print warning message if a Method does not support the :owner method
27
+ if !options[:suppress_slowness_warning] && ! Method.instance_methods.include?("owner")
28
+ STDERR.puts "You are using a Ruby version (#{RUBY_VERSION}) that does not support the owner method of a Method - this may take a while. It will be faster for >=1.8.7."
28
29
  end
29
30
 
30
- methods = []
31
- methods += object.methods if options[:public_methods]
32
- methods += object.protected_methods if options[:protected_methods]
33
- methods += object.private_methods if options[:private_methods]
34
- methods -= object.singleton_methods unless options[:singleton_methods]
35
-
36
31
  ancestor_method_structure = AncestorMethodStructure.new(object, options)
37
-
38
- if(match = options[:match])
39
- unless match.is_a?(Regexp)
40
- match = Regexp.new(match)
41
- end
42
- methods = methods.select { |m| m =~ match }
43
- end
44
-
45
- methods.each do |method|
46
- ancestor_method_structure.add_method_to_ancestor(method)
47
- end
32
+ ancestor_method_structure.add_selected_methods_to_structure
48
33
  ancestor_method_structure
49
34
  end
50
35
 
@@ -130,8 +115,33 @@ module MethodInfo
130
115
  s
131
116
  end
132
117
 
118
+ def add_selected_methods_to_structure
119
+ select_methods
120
+ apply_match_filter_to_methods
121
+ @methods.each do |method|
122
+ add_method_to_ancestor(method)
123
+ end
124
+ end
125
+
133
126
  private
134
127
 
128
+ def select_methods
129
+ @methods = []
130
+ @methods += @object.methods if @options[:public_methods]
131
+ @methods += @object.protected_methods if @options[:protected_methods]
132
+ @methods += @object.private_methods if @options[:private_methods]
133
+ @methods -= @object.singleton_methods unless @options[:singleton_methods]
134
+ end
135
+
136
+ def apply_match_filter_to_methods
137
+ if(match = @options[:match])
138
+ unless match.is_a?(Regexp)
139
+ match = Regexp.new(match)
140
+ end
141
+ @methods = @methods.select { |m| m =~ match }
142
+ end
143
+ end
144
+
135
145
  def methodless_ancestors
136
146
  @ancestor_filter.picked.select { |ancestor| @ancestor_methods[ancestor].empty? }
137
147
  end
@@ -8,7 +8,31 @@ module MethodInfo
8
8
  end
9
9
 
10
10
  describe "AncestorMethodStructure::build" do
11
- it "should print the methods on an object" do
11
+ describe "if a Method does not support the :owner method" do
12
+ before do
13
+ Method.stub!(:instance_methods).and_return ["foo"]
14
+ end
15
+
16
+ it "should print a warning message" do
17
+ STDERR.should_receive :puts
18
+ AncestorMethodStructure.build(:foo, {})
19
+ end
20
+
21
+ it "should not print a warning message if :suppress_slowness_warning is set" do
22
+ STDERR.should_not_receive :puts
23
+ AncestorMethodStructure.build(:foo, :suppress_slowness_warning => true)
24
+ end
25
+ end
26
+
27
+ describe "if a Method supports the :owner method" do
28
+ before do
29
+ Method.stub!(:instance_methods).and_return ["foo", "owner"]
30
+ end
31
+
32
+ it "should not print a warning message" do
33
+ STDERR.should_not_receive :puts
34
+ AncestorMethodStructure.build(:foo, {})
35
+ end
12
36
  end
13
37
  end
14
38
 
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_info
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 9
9
- version: 0.1.9
4
+ version: 0.1.10
10
5
  platform: ruby
11
6
  authors:
12
7
  - Tom ten Thij
@@ -14,35 +9,29 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-02-27 00:00:00 +00:00
12
+ date: 2010-03-18 00:00:00 +00:00
18
13
  default_executable:
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: rspec
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 2
30
- - 9
31
23
  version: 1.2.9
32
- type: :development
33
- version_requirements: *id001
24
+ version:
34
25
  - !ruby/object:Gem::Dependency
35
26
  name: cucumber
36
- prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
38
30
  requirements:
39
31
  - - ">="
40
32
  - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
33
  version: "0"
44
- type: :development
45
- version_requirements: *id002
34
+ version:
46
35
  description: Defines a method_info method on every Object instance which provides information about methods that are defined on the object and the location where they were defined
47
36
  email: method_info@tomtenthij.nl
48
37
  executables: []
@@ -87,20 +76,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
76
  requirements:
88
77
  - - ">="
89
78
  - !ruby/object:Gem::Version
90
- segments:
91
- - 0
92
79
  version: "0"
80
+ version:
93
81
  required_rubygems_version: !ruby/object:Gem::Requirement
94
82
  requirements:
95
83
  - - ">="
96
84
  - !ruby/object:Gem::Version
97
- segments:
98
- - 0
99
85
  version: "0"
86
+ version:
100
87
  requirements: []
101
88
 
102
89
  rubyforge_project:
103
- rubygems_version: 1.3.6
90
+ rubygems_version: 1.3.5
104
91
  signing_key:
105
92
  specification_version: 3
106
93
  summary: Get info about an object's methods