method_info 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -1
- data/VERSION +1 -1
- data/lib/method_info/ancestor_method_structure.rb +14 -9
- data/lib/method_info/object_method.rb +8 -1
- data/lib/method_info/option_handler.rb +6 -2
- data/spec/method_info/ancestor_method_structure_spec.rb +11 -0
- data/spec/method_info/option_handler_spec.rb +9 -3
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -16,8 +16,13 @@ Defines a method_info method on every Object which will show the methods that ea
|
|
16
16
|
* :protected_methods (default: false)
|
17
17
|
* :private_methods (default: false)
|
18
18
|
* :singleton_methods (default: true)
|
19
|
-
* :
|
19
|
+
* :include_names_of_excluded_ancestors (default: true)
|
20
|
+
* :include_names_of_methodless_ancestors (default: true)
|
20
21
|
* :enable_colors (default: false)
|
22
|
+
* :class_color Set colour for a line printing out a class (only used when :enable_colors is true)
|
23
|
+
* :module_color Set colour for a line printing out a module (only used when :enable_colors is true)
|
24
|
+
* :message_color Set colour for a line with a message (only used when :enable_colors is true)
|
25
|
+
* :methods_color Set colour for a line with methods (only used when :enable_colors is true)
|
21
26
|
|
22
27
|
You can set default options which will override the inbuild defaults. Here is an example which
|
23
28
|
will hide the methods defined on all instances of Object and show colour in the output (this
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
@@ -64,29 +64,34 @@ module MethodInfo
|
|
64
64
|
if @options[:enable_colors]
|
65
65
|
require 'term/ansicolor'
|
66
66
|
|
67
|
-
class_color = Term::ANSIColor.yellow
|
68
|
-
module_color = Term::ANSIColor.red
|
69
|
-
message_color = Term::ANSIColor.green
|
70
|
-
|
67
|
+
class_color = @options[:color_class] || Term::ANSIColor.yellow
|
68
|
+
module_color = @options[:color_module] || Term::ANSIColor.red
|
69
|
+
message_color = @options[:color_message] || Term::ANSIColor.green
|
70
|
+
methods_color = @options[:color_methods] || Term::ANSIColor.reset
|
71
|
+
punctuation_color = @options[:color_punctuation] || Term::ANSIColor.reset
|
72
|
+
reset_color = Term::ANSIColor.reset
|
71
73
|
else
|
72
74
|
class_color = ""
|
73
75
|
module_color = ""
|
74
76
|
message_color = ""
|
77
|
+
methods_color = ""
|
75
78
|
reset_color = ""
|
79
|
+
punctuation_color = ""
|
76
80
|
end
|
77
81
|
|
78
82
|
s = ancestors_with_methods.map do |ancestor|
|
79
83
|
"%s::: %s :::\n%s%s\n" % [ancestor.is_a?(Class) ? class_color : module_color,
|
80
84
|
ancestor.to_s,
|
81
|
-
|
82
|
-
@ancestor_methods[ancestor].sort.join(
|
85
|
+
methods_color,
|
86
|
+
@ancestor_methods[ancestor].sort.join("#{punctuation_color}, #{methods_color}")]
|
83
87
|
end.join('')
|
84
|
-
if @options[:
|
88
|
+
if @options[:include_names_of_methodless_ancestors] && ! methodless_ancestors.empty?
|
85
89
|
s += "#{message_color}Methodless:#{reset_color} " + methodless_ancestors.join(', ') + "\n"
|
86
90
|
end
|
87
|
-
if @options[:
|
91
|
+
if @options[:include_names_of_excluded_ancestors] && ! @ancestor_filter.excluded.empty?
|
88
92
|
s += "#{message_color}Excluded:#{reset_color} " + @ancestor_filter.excluded.join(', ') + "\n"
|
89
93
|
end
|
94
|
+
s += reset_color
|
90
95
|
s
|
91
96
|
end
|
92
97
|
|
@@ -104,7 +109,7 @@ module MethodInfo
|
|
104
109
|
def method_owner(method_symbol)
|
105
110
|
method = @object.method(method_symbol)
|
106
111
|
method.owner
|
107
|
-
rescue
|
112
|
+
rescue NameError
|
108
113
|
poor_mans_method_owner(method, method_symbol.to_s)
|
109
114
|
end
|
110
115
|
|
@@ -18,7 +18,14 @@ module MethodInfo
|
|
18
18
|
# :protected_methods (default: false)
|
19
19
|
# :private_methods (default: false)
|
20
20
|
# :singleton_methods (default: true)
|
21
|
-
# :
|
21
|
+
# :include_names_of_excluded_ancestors (default: true)
|
22
|
+
# :include_names_of_methodless_ancestors (default: true)
|
23
|
+
# :enable_colors (default: false)
|
24
|
+
# :class_color Set colour for a line printing out a class (only used when :enable_colors is true)
|
25
|
+
# :module_color Set colour for a line printing out a module (only used when :enable_colors is true)
|
26
|
+
# :message_color Set colour for a line with a message (only used when :enable_colors is true)
|
27
|
+
# :methods_color Set colour for a line with methods (only used when :enable_colors is true)
|
28
|
+
# :punctuation_color Set colour for punctuation (only used when :enable_colors is true)
|
22
29
|
def method_info(options = {})
|
23
30
|
OptionHandler.handle(self, options)
|
24
31
|
end
|
@@ -24,8 +24,8 @@ module MethodInfo
|
|
24
24
|
:ancestors_to_show => [],
|
25
25
|
:ancestors_to_exclude => [],
|
26
26
|
:format => nil,
|
27
|
-
:
|
28
|
-
:
|
27
|
+
:include_names_of_excluded_ancestors => true,
|
28
|
+
:include_names_of_methodless_ancestors => true,
|
29
29
|
:private_methods => false,
|
30
30
|
:protected_methods => false,
|
31
31
|
:singleton_methods => true,
|
@@ -38,6 +38,10 @@ module MethodInfo
|
|
38
38
|
@@custom_default_options = options
|
39
39
|
end
|
40
40
|
|
41
|
+
def self.default_options
|
42
|
+
@@custom_default_options
|
43
|
+
end
|
44
|
+
|
41
45
|
def self.process_options(options = {})
|
42
46
|
defaults = default_profile.merge(@@custom_default_options)
|
43
47
|
unknown_options = options.keys - defaults.keys
|
@@ -48,6 +48,17 @@ module MethodInfo
|
|
48
48
|
ams.send(:method_owner, :to_i)
|
49
49
|
end
|
50
50
|
|
51
|
+
it "raises an error if an error is raised that is not a NameError" do
|
52
|
+
obj = mock('object')
|
53
|
+
mock_method = mock('method', :to_s => 'mock_method_name')
|
54
|
+
obj.stub!(:method).and_return(mock_method)
|
55
|
+
mock_method.stub!(:owner).and_raise ArgumentError
|
56
|
+
ams = AncestorMethodStructure.new(obj,
|
57
|
+
:ancestors_to_show => [],
|
58
|
+
:ancestors_to_exclude => [])
|
59
|
+
lambda { ams.send(:method_owner, :to_i) }.should raise_error(ArgumentError)
|
60
|
+
end
|
61
|
+
|
51
62
|
describe "poor_mans_method_owner" do
|
52
63
|
it "finds the owner if it is the base clas" do
|
53
64
|
ams = AncestorMethodStructure.new(37, {})
|
@@ -43,12 +43,13 @@ module MethodInfo
|
|
43
43
|
default_options[:format].should == nil
|
44
44
|
default_options[:ancestors_to_show].should == []
|
45
45
|
default_options[:ancestors_to_exclude].should == []
|
46
|
-
default_options[:
|
47
|
-
default_options[:
|
46
|
+
default_options[:include_names_of_excluded_ancestors].should == true
|
47
|
+
default_options[:include_names_of_methodless_ancestors].should == true
|
48
48
|
default_options[:public_methods].should == true
|
49
49
|
default_options[:singleton_methods].should == true
|
50
50
|
default_options[:protected_methods].should == false
|
51
51
|
default_options[:private_methods].should == false
|
52
|
+
default_options[:enable_colors].should == false
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
@@ -100,7 +101,7 @@ module MethodInfo
|
|
100
101
|
end
|
101
102
|
|
102
103
|
describe "setting default options" do
|
103
|
-
it "
|
104
|
+
it "uses a value that is set in the default options" do
|
104
105
|
MethodInfo::OptionHandler.default_options = {
|
105
106
|
:ancestors_to_exclude => [Object]
|
106
107
|
}
|
@@ -110,5 +111,10 @@ module MethodInfo
|
|
110
111
|
MethodInfo::OptionHandler.handle(:foo)
|
111
112
|
end
|
112
113
|
end
|
114
|
+
|
115
|
+
it "provides access to it's default options" do
|
116
|
+
MethodInfo::OptionHandler.default_options[:foo] = :bar
|
117
|
+
MethodInfo::OptionHandler.default_options.should == { :foo => :bar }
|
118
|
+
end
|
113
119
|
end
|
114
120
|
end
|