method_info 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +22 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/features/method_info.feature +9 -0
- data/features/step_definitions/method_info_steps.rb +0 -0
- data/features/support/env.rb +4 -0
- data/lib/method_info.rb +42 -0
- data/spec/method_info_spec.rb +111 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- metadata +88 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Tom ten Thij
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= method_info
|
2
|
+
|
3
|
+
Provides info about methods that can be called on an object and where they are defined.
|
4
|
+
|
5
|
+
Usage:
|
6
|
+
|
7
|
+
require 'method_info'
|
8
|
+
"abc".method_info
|
9
|
+
|
10
|
+
== Note on Patches/Pull Requests
|
11
|
+
|
12
|
+
* Fork the project.
|
13
|
+
* Make your feature addition or bug fix.
|
14
|
+
* Add tests for it. This is important so I don't break it in a
|
15
|
+
future version unintentionally.
|
16
|
+
* Commit, do not mess with rakefile, version, or history.
|
17
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
18
|
+
* Send me a pull request. Bonus points for topic branches.
|
19
|
+
|
20
|
+
== Copyright
|
21
|
+
|
22
|
+
Copyright (c) 2010 Tom ten Thij. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "method_info"
|
8
|
+
gem.summary = %Q{Get info about an object's methods}
|
9
|
+
gem.description = %Q{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}
|
10
|
+
gem.email = "method_info@tomtenthij.nl"
|
11
|
+
gem.homepage = "http://github.com/tomtt/method_info"
|
12
|
+
gem.authors = ["Tom ten Thij"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_development_dependency "cucumber", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'cucumber/rake/task'
|
38
|
+
Cucumber::Rake::Task.new(:features)
|
39
|
+
|
40
|
+
task :features => :check_dependencies
|
41
|
+
rescue LoadError
|
42
|
+
task :features do
|
43
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
task :default => :spec
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "method_info #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
File without changes
|
data/lib/method_info.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
module MethodInfoMethod
|
3
|
+
def method_info
|
4
|
+
MethodInfo.new(self)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Object
|
9
|
+
include MethodInfoMethod
|
10
|
+
end
|
11
|
+
|
12
|
+
class MethodInfo
|
13
|
+
def initialize(object)
|
14
|
+
@object = object
|
15
|
+
unless @object.singleton_methods.empty?
|
16
|
+
@eigenclass = class << object; self; end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def ancestors
|
21
|
+
@ancestors = []
|
22
|
+
if @eigenclass
|
23
|
+
@ancestors << @eigenclass
|
24
|
+
end
|
25
|
+
@ancestors += @object.class.ancestors
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_owner(method)
|
29
|
+
@object.method(method).owner
|
30
|
+
end
|
31
|
+
|
32
|
+
def method_owner!(method)
|
33
|
+
method_owner(method)
|
34
|
+
rescue NameError => e
|
35
|
+
begin
|
36
|
+
@object.send(method)
|
37
|
+
method_owner(:method_missing)
|
38
|
+
rescue NoMethodError
|
39
|
+
raise e
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe MethodInfo do
|
4
|
+
describe "ancestors" do
|
5
|
+
it "has the ancestors that a String has on any system for a String object" do
|
6
|
+
ancestors = 37.method_info.ancestors
|
7
|
+
usual_ancestors = [Fixnum, Integer, Precision, Numeric, Comparable, Object, Kernel]
|
8
|
+
ancestors_without_system_specific_ones = ancestors.
|
9
|
+
select { |ancestor| usual_ancestors.include?(ancestor) }
|
10
|
+
ancestors_without_system_specific_ones.should == usual_ancestors
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not contain a module that was not included" do
|
14
|
+
class Forest
|
15
|
+
end
|
16
|
+
sherwood = Forest.new
|
17
|
+
sherwood.method_info.ancestors.should_not include(Enumerable)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "contains an included module" do
|
21
|
+
class Zoo
|
22
|
+
include(Enumerable)
|
23
|
+
end
|
24
|
+
artis = Zoo.new
|
25
|
+
artis.method_info.ancestors.should include(Enumerable)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has an object's eigenclass as the first element if it has singleton methods" do
|
29
|
+
monkey = Object.new
|
30
|
+
def monkey.talk
|
31
|
+
"Ook!"
|
32
|
+
end
|
33
|
+
eigenclass_of_monkey = class << monkey; self; end
|
34
|
+
monkey.method_info.ancestors.first.should == eigenclass_of_monkey
|
35
|
+
end
|
36
|
+
|
37
|
+
it "does not include the object's eigenclass if it has no singleton methods" do
|
38
|
+
monkey = Object.new
|
39
|
+
eigenclass_of_monkey = class << monkey; self; end
|
40
|
+
monkey.method_info.ancestors.should_not include(eigenclass_of_monkey)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "method_owner" do
|
45
|
+
class AbstractMethodOwnerDummy
|
46
|
+
def abstract_instance_method
|
47
|
+
:abstract_instance_method
|
48
|
+
end
|
49
|
+
|
50
|
+
def duplicate_instance_method
|
51
|
+
:abstract_duplicate_instance_method
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class ConcreteMethodOwnerDummy < AbstractMethodOwnerDummy
|
56
|
+
def concrete_instance_method
|
57
|
+
:concrete_instance_method
|
58
|
+
end
|
59
|
+
|
60
|
+
def duplicate_instance_method
|
61
|
+
:concrete_duplicate_instance_method
|
62
|
+
end
|
63
|
+
|
64
|
+
def method_missing(method)
|
65
|
+
if method == :missing_method_handled_at_concrete
|
66
|
+
return :missing_method_handled_at_concrete
|
67
|
+
end
|
68
|
+
super
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "is the class of the object for an instance_method" do
|
73
|
+
ConcreteMethodOwnerDummy.new.method_info.method_owner(:concrete_instance_method).should ==
|
74
|
+
ConcreteMethodOwnerDummy
|
75
|
+
end
|
76
|
+
|
77
|
+
it "is the superclass of an objects class if that is where the method is first defined" do
|
78
|
+
ConcreteMethodOwnerDummy.new.method_info.method_owner(:abstract_instance_method).should ==
|
79
|
+
AbstractMethodOwnerDummy
|
80
|
+
end
|
81
|
+
|
82
|
+
it "raises an error if the object does not respond to the method" do
|
83
|
+
lambda { ConcreteMethodOwnerDummy.new.method_info.method_owner(:poof) }.should raise_error(NameError)
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "method_owner!" do
|
87
|
+
it "is the class of the object for an instance_method" do
|
88
|
+
ConcreteMethodOwnerDummy.new.method_info.method_owner!(:concrete_instance_method).should ==
|
89
|
+
ConcreteMethodOwnerDummy
|
90
|
+
end
|
91
|
+
|
92
|
+
it "is the superclass of an objects class if that is where the method is first defined" do
|
93
|
+
ConcreteMethodOwnerDummy.new.method_info.method_owner!(:abstract_instance_method).should ==
|
94
|
+
AbstractMethodOwnerDummy
|
95
|
+
end
|
96
|
+
|
97
|
+
it "raises an error if the object does not respond to the method" do
|
98
|
+
lambda { ConcreteMethodOwnerDummy.new.method_info.method_owner!(:poof) }.should raise_error(NameError)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "is the first method missing method if there is one that handles the method" do
|
102
|
+
ConcreteMethodOwnerDummy.new.method_info.method_owner!(:missing_method_handled_at_concrete).should ==
|
103
|
+
"ConcreteMethodOwnerDummy::method_missing"
|
104
|
+
end
|
105
|
+
|
106
|
+
it "raises an error if the object does not respond to the method" do
|
107
|
+
lambda { ConcreteMethodOwnerDummy.new.method_info.method_owner!(:poof) }.should raise_error(NameError)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: method_info
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom ten Thij
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-10 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: cucumber
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
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
|
36
|
+
email: method_info@tomtenthij.nl
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- features/method_info.feature
|
52
|
+
- features/step_definitions/method_info_steps.rb
|
53
|
+
- features/support/env.rb
|
54
|
+
- lib/method_info.rb
|
55
|
+
- spec/method_info_spec.rb
|
56
|
+
- spec/spec.opts
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://github.com/tomtt/method_info
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --charset=UTF-8
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.5
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Get info about an object's methods
|
86
|
+
test_files:
|
87
|
+
- spec/method_info_spec.rb
|
88
|
+
- spec/spec_helper.rb
|