reflectorr 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -106,6 +106,10 @@ available yet. So keep this in mind also.
106
106
 
107
107
  So have fun, I hope you'll learn from it, and find it useful. If not, just discard this :).
108
108
 
109
+ == History
110
+
111
+ 0.2.0: Total rewrite in order to include more ways of extending/excluding your class in the result.
112
+
109
113
  == Note on Patches/Pull Requests
110
114
 
111
115
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/reflectorr.rb CHANGED
@@ -1,21 +1,29 @@
1
- #module ShowMethods
2
1
  class Object
3
2
  def show_methods
4
3
  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
4
+ self.class.ancestors.each do |a|
5
+ result[a.name]=[]
6
+ a.instance_methods(false).sort.each do |m|
7
+ result[a.name].push m
8
+ end
9
+ end
10
+ result
11
+ end
12
+ def self.show_methods
13
+ result = {}
14
+ metaclass = class << self; self; end
15
+ self.ancestors.each do |a|
16
+ result[a.name] ||= []
17
+ a.singleton_methods(false).sort.each do |m|
18
+ result[a.name].push m
19
+ end
20
+ end
21
+ metaclass.ancestors.each do |a|
22
+ result[a.name] ||= []
23
+ a.instance_methods(false).sort.each do |m|
24
+ result[a.name].push m
25
+ end
17
26
  end
18
27
  result
19
28
  end
20
29
  end
21
- #end
data/reflectorr.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{reflectorr}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Christiaan Van den Poel"]
12
- s.date = %q{2010-02-24}
12
+ s.date = %q{2010-03-16}
13
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
14
  s.email = %q{christiaan@oneye.be}
15
15
  s.extra_rdoc_files = [
@@ -1,24 +1,47 @@
1
+ module Helpers
2
+ def first_helper
3
+
4
+ end
5
+ def self.second_helper
6
+ end
7
+ end
8
+
9
+ module ClassMethods
10
+ def class_method
11
+
12
+ end
13
+ end
14
+
15
+ module HelpersViaInclude
16
+ def self.included(klass)
17
+ klass.send(:extend ,ClassMethods)
18
+ end
19
+ module ClassMethods
20
+ def included_class_method
21
+
22
+ end
23
+ end
24
+ end
25
+
1
26
  module ShowMethods
2
27
  module Fixtures
3
- class FirstClass
4
- def simple_method
5
- {}
28
+ class ClassWithSomeMethods
29
+ include ::Helpers
30
+ extend ::ClassMethods
31
+ include ::HelpersViaInclude
32
+ def one
33
+
6
34
  end
7
- end
8
- class SecondClass < FirstClass
9
- def second_simple_method
10
- ""
35
+ def two
36
+
11
37
  end
12
- end
13
- class ThirdClass
14
- def self.third_method
15
- ""
38
+ def self.three
39
+
16
40
  end
17
- end
18
- class FourthClass < ThirdClass
19
- def self.fourth_method
41
+ def self.four
20
42
 
21
43
  end
22
44
  end
23
45
  end
24
46
  end
47
+
@@ -1,55 +1,39 @@
1
1
  require 'helper'
2
+ require 'json'
2
3
 
3
4
  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
5
+ context "Class With some instance methods" do
6
+ setup do
7
+ @result = ShowMethods::Fixtures::ClassWithSomeMethods.new.show_methods
14
8
  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
9
+ should "show the instance methods from its own class" do
10
+ assert @result.has_key?("ShowMethods::Fixtures::ClassWithSomeMethods")
11
+ assert_same_elements @result["ShowMethods::Fixtures::ClassWithSomeMethods"], ["one", "two"]
12
+ end
13
+ should "show the methods from the included Helpers module" do
14
+ assert @result.has_key?("Helpers")
15
+ assert_same_elements @result["Helpers"], ["first_helper"]
29
16
  end
30
17
  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
18
+ context "class with some class methods" do
19
+ setup do
20
+ @result = ShowMethods::Fixtures::ClassWithSomeMethods.show_methods
21
+ end
22
+ should "show the class methods" do
23
+ assert @result.has_key?("ShowMethods::Fixtures::ClassWithSomeMethods")
24
+ assert_same_elements @result["ShowMethods::Fixtures::ClassWithSomeMethods"], ["three", "four"]
25
+ end
26
+ should "show the class methods defined in another module" do
27
+ assert @result.has_key?("Helpers")
28
+ assert_same_elements @result["Helpers"], ["second_helper"]
29
+ end
30
+ should "show the class methods from the module via extend" do
31
+ assert @result.has_key?("ClassMethods")
32
+ assert_same_elements @result["ClassMethods"], ["class_method"]
33
+ end
34
+ should "show the class methods from the HelpersViaInclude module" do
35
+ assert @result.has_key?("HelpersViaInclude::ClassMethods")
36
+ assert_same_elements @result["HelpersViaInclude::ClassMethods"], ["included_class_method"]
53
37
  end
54
38
  end
55
39
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Christiaan Van den Poel
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-02-24 00:00:00 +01:00
17
+ date: 2010-03-16 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency