reflectorr 0.1.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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +121 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/reflectorr.rb +21 -0
- data/reflectorr.gemspec +56 -0
- data/test/fixtures/first_class.rb +24 -0
- data/test/helper.rb +14 -0
- data/test/test_show_methods.rb +55 -0
- metadata +86 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Christiaan Van den Poel
|
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,121 @@
|
|
1
|
+
= Reflectorr
|
2
|
+
|
3
|
+
Ruby is a great and powerful language, you can do some really cool stuff. But sometimes, as a developer, you're typing some code and you are
|
4
|
+
at a place where you wished you had some superintelligent, real cool context-sensitive intellisense that you could use to see which method exactly
|
5
|
+
you can use at that place. But we all use {vim|emacs|textmate|...} which are simple but effective editors. Although there's some completion you
|
6
|
+
can use, it will not provide completion for some fancy module you've included, but you know it's there.
|
7
|
+
Sure, you can go through the documentation, but still you're not sure whether it is there or not.
|
8
|
+
|
9
|
+
I find myself, from time to time, wondering "what methods can I use here?". Sure, I can fireup Rubymine and hope it's intelligent enough
|
10
|
+
to interpret my whole project and tell me perfectly all the methods I can use when I tab CTRL-SPACE. Most of the times, I'm disappointed
|
11
|
+
by the fact Im not getting what I wanted.
|
12
|
+
|
13
|
+
Enter 'reflectorr', it provides one single method called 'show_methods' which you can use everywhere in your code and it returns a hash
|
14
|
+
containing every included module as the key and an array of methods you can call at that place where you called it.
|
15
|
+
|
16
|
+
An example:
|
17
|
+
|
18
|
+
require 'pp'
|
19
|
+
require 'reflectorr'
|
20
|
+
class MyClass
|
21
|
+
def an_instance_method
|
22
|
+
end
|
23
|
+
def self.a_class_method
|
24
|
+
end
|
25
|
+
pp show_methods
|
26
|
+
def self.a_second_class_method
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
And this will return this
|
31
|
+
|
32
|
+
{"Object"=> ["yaml_tag_subclasses?"],
|
33
|
+
"PP::ObjectMixin"=>[],
|
34
|
+
"Kernel"=> ["test",
|
35
|
+
"callcc",
|
36
|
+
"gsub",
|
37
|
+
"String",
|
38
|
+
"exit",
|
39
|
+
"require",
|
40
|
+
"trap",
|
41
|
+
"proc",
|
42
|
+
"`",
|
43
|
+
"fork",
|
44
|
+
"global_variables",
|
45
|
+
"print",
|
46
|
+
"chomp!",
|
47
|
+
"sprintf",
|
48
|
+
"Integer",
|
49
|
+
"fail",
|
50
|
+
"rand",
|
51
|
+
"autoload?",
|
52
|
+
"readlines",
|
53
|
+
"catch",
|
54
|
+
"exit!",
|
55
|
+
"open",
|
56
|
+
"gsub!",
|
57
|
+
"set_trace_func",
|
58
|
+
"gets",
|
59
|
+
"sleep",
|
60
|
+
"iterator?",
|
61
|
+
"select",
|
62
|
+
"autoload",
|
63
|
+
"getc",
|
64
|
+
"chop",
|
65
|
+
"Array",
|
66
|
+
"abort",
|
67
|
+
"pp",
|
68
|
+
"lambda",
|
69
|
+
"trace_var",
|
70
|
+
"method_missing",
|
71
|
+
"format",
|
72
|
+
"local_variables",
|
73
|
+
"putc",
|
74
|
+
"exec",
|
75
|
+
"split",
|
76
|
+
"sub",
|
77
|
+
"Float",
|
78
|
+
"caller",
|
79
|
+
"load",
|
80
|
+
"eval",
|
81
|
+
"binding",
|
82
|
+
"p",
|
83
|
+
"chop!",
|
84
|
+
"URI",
|
85
|
+
"throw",
|
86
|
+
"printf",
|
87
|
+
"srand",
|
88
|
+
"raise",
|
89
|
+
"readline",
|
90
|
+
"block_given?",
|
91
|
+
"at_exit",
|
92
|
+
"syscall",
|
93
|
+
"sub!",
|
94
|
+
"chomp",
|
95
|
+
"scan",
|
96
|
+
"loop",
|
97
|
+
"untrace_var",
|
98
|
+
"warn",
|
99
|
+
"system",
|
100
|
+
"__method__",
|
101
|
+
"puts"],
|
102
|
+
"MyClass"=> ["a_class_method"]}
|
103
|
+
|
104
|
+
You can see it will show for 'MyClass' only the method 'a_class_method'. 'a_second_class_method' is defined after the 'show_methods' call and isn't
|
105
|
+
available yet. So keep this in mind also.
|
106
|
+
|
107
|
+
So have fun, I hope you'll learn from it, and find it useful. If not, just discard this :).
|
108
|
+
|
109
|
+
== Note on Patches/Pull Requests
|
110
|
+
|
111
|
+
* Fork the project.
|
112
|
+
* Make your feature addition or bug fix.
|
113
|
+
* Add tests for it. This is important so I don't break it in a
|
114
|
+
future version unintentionally.
|
115
|
+
* Commit, do not mess with rakefile, version, or history.
|
116
|
+
(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)
|
117
|
+
* Send me a pull request. Bonus points for topic branches.
|
118
|
+
|
119
|
+
== Copyright
|
120
|
+
|
121
|
+
Copyright (c) 2010 Christiaan Van den Poel. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "reflectorr"
|
8
|
+
gem.summary = %Q{Show me the methods}
|
9
|
+
gem.description = %Q{This simple gem will show you all the methods you can use at the place where you call the method 'show_methods'}
|
10
|
+
gem.email = "christiaan@oneye.be"
|
11
|
+
gem.homepage = "http://github.com/khelben/reflectorr"
|
12
|
+
gem.authors = ["Christiaan Van den Poel"]
|
13
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "reflectorr #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/reflectorr.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#module ShowMethods
|
2
|
+
class Object
|
3
|
+
def show_methods
|
4
|
+
result = {}
|
5
|
+
is_eigenklass = self.instance_of?(Class)
|
6
|
+
(is_eigenklass ? self : self.class).ancestors.each do |a|
|
7
|
+
result[a.name]=[]
|
8
|
+
if is_eigenklass
|
9
|
+
a.singleton_methods(false).each do |m|
|
10
|
+
result[a.name].push m
|
11
|
+
end
|
12
|
+
else
|
13
|
+
a.instance_methods(false).each do |m|
|
14
|
+
result[a.name].push m
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
#end
|
data/reflectorr.gemspec
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{reflectorr}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Christiaan Van den Poel"]
|
12
|
+
s.date = %q{2010-02-24}
|
13
|
+
s.description = %q{This simple gem will show you all the methods you can use at the place where you call the method 'show_methods'}
|
14
|
+
s.email = %q{christiaan@oneye.be}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/reflectorr.rb",
|
27
|
+
"reflectorr.gemspec",
|
28
|
+
"test/fixtures/first_class.rb",
|
29
|
+
"test/helper.rb",
|
30
|
+
"test/test_show_methods.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/khelben/reflectorr}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.6}
|
36
|
+
s.summary = %q{Show me the methods}
|
37
|
+
s.test_files = [
|
38
|
+
"test/test_show_methods.rb",
|
39
|
+
"test/helper.rb",
|
40
|
+
"test/fixtures/first_class.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ShowMethods
|
2
|
+
module Fixtures
|
3
|
+
class FirstClass
|
4
|
+
def simple_method
|
5
|
+
{}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
class SecondClass < FirstClass
|
9
|
+
def second_simple_method
|
10
|
+
""
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class ThirdClass
|
14
|
+
def self.third_method
|
15
|
+
""
|
16
|
+
end
|
17
|
+
end
|
18
|
+
class FourthClass < ThirdClass
|
19
|
+
def self.fourth_method
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
require 'reflectorr'
|
8
|
+
# require everything in the 'fixtures/*' folders
|
9
|
+
Dir[File.dirname(__FILE__) + "/fixtures/**/*.rb"].each do |f|
|
10
|
+
require f
|
11
|
+
end
|
12
|
+
|
13
|
+
class Test::Unit::TestCase
|
14
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestShowMethods < Test::Unit::TestCase
|
4
|
+
context "instance methods" do
|
5
|
+
context "simple_methods" do
|
6
|
+
should "show the method" do
|
7
|
+
result = ShowMethods::Fixtures::FirstClass.new.send(:show_methods)
|
8
|
+
assert result.is_a?(Hash), "Result should be an Hash"
|
9
|
+
"ShowMethods::Fixtures::FirstClass".tap do |m|
|
10
|
+
assert result.has_key?(m), "the module ShowMethods should be a key in the result hash"
|
11
|
+
assert_contains result[m], "simple_method", "the method 'simple_method' should be in the result"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "subclass" do
|
17
|
+
should "show methods of superclass" do
|
18
|
+
result = ShowMethods::Fixtures::SecondClass.new.send(:show_methods)
|
19
|
+
assert result.is_a?(Hash), "Result should be an Hash"
|
20
|
+
"ShowMethods::Fixtures::SecondClass".tap do |m|
|
21
|
+
assert result.has_key?(m)
|
22
|
+
assert_contains result[m], "second_simple_method"
|
23
|
+
end
|
24
|
+
"ShowMethods::Fixtures::FirstClass".tap do |m|
|
25
|
+
assert result.has_key?(m), "the module ShowMethods should be a key in the result hash"
|
26
|
+
assert_contains result[m], "simple_method", "the method 'simple_method' should be in the result"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
context "class methods" do
|
32
|
+
context "third_method" do
|
33
|
+
should "show the method" do
|
34
|
+
result = ShowMethods::Fixtures::ThirdClass.send(:show_methods)
|
35
|
+
"ShowMethods::Fixtures::ThirdClass".tap do |m|
|
36
|
+
assert result.has_key?(m)
|
37
|
+
assert_contains result[m], "third_method"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context "subclass" do
|
42
|
+
should "show class methods from FourthClass and ThirdClass" do
|
43
|
+
result = ShowMethods::Fixtures::FourthClass.send(:show_methods)
|
44
|
+
"ShowMethods::Fixtures::FourthClass".tap do |m|
|
45
|
+
assert result.has_key?(m)
|
46
|
+
assert_contains result[m], "fourth_method"
|
47
|
+
end
|
48
|
+
"ShowMethods::Fixtures::ThirdClass".tap do |m|
|
49
|
+
assert result.has_key?(m)
|
50
|
+
assert_contains result[m], "third_method"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reflectorr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Christiaan Van den Poel
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-02-24 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
description: This simple gem will show you all the methods you can use at the place where you call the method 'show_methods'
|
33
|
+
email: christiaan@oneye.be
|
34
|
+
executables: []
|
35
|
+
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- LICENSE
|
40
|
+
- README.rdoc
|
41
|
+
files:
|
42
|
+
- .document
|
43
|
+
- .gitignore
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
- Rakefile
|
47
|
+
- VERSION
|
48
|
+
- lib/reflectorr.rb
|
49
|
+
- reflectorr.gemspec
|
50
|
+
- test/fixtures/first_class.rb
|
51
|
+
- test/helper.rb
|
52
|
+
- test/test_show_methods.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/khelben/reflectorr
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options:
|
59
|
+
- --charset=UTF-8
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.6
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Show me the methods
|
83
|
+
test_files:
|
84
|
+
- test/test_show_methods.rb
|
85
|
+
- test/helper.rb
|
86
|
+
- test/fixtures/first_class.rb
|