sender 1.4.2 → 1.4.3
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/CHANGELOG.rdoc +5 -1
- data/README.rdoc +51 -20
- data/VERSION.rdoc +1 -1
- data/ext/sender/rb_Global.c +59 -11
- data/lib/VERSION.rdoc +1 -1
- data/lib/sender/sender.bundle +0 -0
- data/sender.gemspec +1 -1
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
@@ -35,4 +35,8 @@ __sender__ and __caller__ now work for :initialize and return the object and met
|
|
35
35
|
|
36
36
|
=== 1.4.1-2 2010-06-29
|
37
37
|
|
38
|
-
Fixed path problem for VERSION.rdoc.
|
38
|
+
Fixed path problem for VERSION.rdoc.
|
39
|
+
|
40
|
+
=== 1.4.3 2010-06-29
|
41
|
+
|
42
|
+
Fixed problems with superclass method definitions so __sender__ and __caller__ return the caller to the first method in the class chain.
|
data/README.rdoc
CHANGED
@@ -28,7 +28,7 @@ which allows contents of the backtrace to be queried.
|
|
28
28
|
|
29
29
|
== EXAMPLE:
|
30
30
|
|
31
|
-
require '
|
31
|
+
require 'sender'
|
32
32
|
|
33
33
|
require 'pp'
|
34
34
|
|
@@ -51,18 +51,27 @@ which allows contents of the backtrace to be queried.
|
|
51
51
|
test2.and_another_test_in_another_object
|
52
52
|
end
|
53
53
|
|
54
|
+
def and_another_test_in_another_object
|
55
|
+
puts 'In method <Test>:and_another_test_in_another_object'
|
56
|
+
puts 'Sender was: ' + __sender__.pretty_inspect.to_s
|
57
|
+
puts 'Caller was: ' + __caller__.to_s
|
58
|
+
end
|
59
|
+
|
54
60
|
end
|
55
61
|
|
56
|
-
class Test2
|
62
|
+
class Test2 < Test
|
57
63
|
|
58
64
|
def initialize
|
59
65
|
puts 'In method <Test2>:initialize'
|
66
|
+
super
|
60
67
|
puts 'Sender was: ' + __sender__.pretty_inspect.to_s
|
61
68
|
puts 'Caller was: ' + __caller__.to_s
|
69
|
+
pp Kernel.backtrace
|
62
70
|
end
|
63
71
|
|
64
72
|
def and_another_test_in_another_object
|
65
73
|
puts 'In method <Test2>:and_another_test_in_another_object'
|
74
|
+
super
|
66
75
|
pp self
|
67
76
|
puts 'Sender was: ' + __sender__.pretty_inspect.to_s
|
68
77
|
puts 'Caller was: ' + __caller__.to_s
|
@@ -87,7 +96,7 @@ which allows contents of the backtrace to be queried.
|
|
87
96
|
|
88
97
|
puts 'Finished Test.'
|
89
98
|
exit
|
90
|
-
|
99
|
+
|
91
100
|
== EXAMPLE's OUTPUT:
|
92
101
|
|
93
102
|
In method <Test>:initialize
|
@@ -96,34 +105,56 @@ which allows contents of the backtrace to be queried.
|
|
96
105
|
In <Test>:test
|
97
106
|
In method <Test>:another_test
|
98
107
|
In method <Test2>:initialize
|
99
|
-
|
108
|
+
In method <Test>:initialize
|
109
|
+
Sender was: #<Test:0x0000010102a400>
|
100
110
|
Caller was: another_test
|
111
|
+
Sender was: #<Test:0x0000010102a400>
|
112
|
+
Caller was: another_test
|
113
|
+
[{:object=>#<Test2:0x00000100823030>,
|
114
|
+
:file=>"sender_test.rb",
|
115
|
+
:line=>40,
|
116
|
+
:method=>:initialize},
|
117
|
+
{:object=>Test2, :file=>nil, :line=>nil, :method=>:new},
|
118
|
+
{:object=>#<Test:0x0000010102a400>,
|
119
|
+
:file=>"sender_test.rb",
|
120
|
+
:line=>20,
|
121
|
+
:method=>:another_test},
|
122
|
+
{:object=>#<Test:0x0000010102a400>,
|
123
|
+
:file=>"sender_test.rb",
|
124
|
+
:line=>15,
|
125
|
+
:method=>:test},
|
126
|
+
{:object=>main, :file=>"sender_test.rb", :line=>66, :method=>:"<main>"},
|
127
|
+
{:object=>main, :file=>"<main>", :line=>0, :method=>:"<main>"}]
|
101
128
|
In method <Test2>:and_another_test_in_another_object
|
102
|
-
|
103
|
-
|
129
|
+
In method <Test>:and_another_test_in_another_object
|
130
|
+
This is the super method for :and_another_test_in_another_object
|
131
|
+
Sender was: #<Test2:0x00000100823030>
|
104
132
|
Caller was: another_test
|
105
|
-
|
133
|
+
#<Test2:0x00000100823030>
|
134
|
+
Sender was: #<Test:0x0000010102a400>
|
135
|
+
Caller was: another_test
|
136
|
+
[{:object=>#<Test2:0x00000100823030>,
|
106
137
|
:file=>"sender_test.rb",
|
107
|
-
:line=>
|
108
|
-
:method
|
109
|
-
{:object=>#<Test:
|
138
|
+
:line=>49,
|
139
|
+
:method=>:and_another_test_in_another_object},
|
140
|
+
{:object=>#<Test:0x0000010102a400>,
|
110
141
|
:file=>"sender_test.rb",
|
111
142
|
:line=>21,
|
112
|
-
:method
|
113
|
-
{:object=>#<Test:
|
143
|
+
:method=>:another_test},
|
144
|
+
{:object=>#<Test:0x0000010102a400>,
|
114
145
|
:file=>"sender_test.rb",
|
115
146
|
:line=>15,
|
116
|
-
:method
|
117
|
-
{:object=>main, :file=>"sender_test.rb", :line=>
|
118
|
-
{:object=>main, :file=>"<main>", :line=>0, :method
|
119
|
-
[{:object=>#<Test2:
|
147
|
+
:method=>:test},
|
148
|
+
{:object=>main, :file=>"sender_test.rb", :line=>66, :method=>:"<main>"},
|
149
|
+
{:object=>main, :file=>"<main>", :line=>0, :method=>:"<main>"}]
|
150
|
+
[{:object=>#<Test2:0x00000100823030>,
|
120
151
|
:file=>"sender_test.rb",
|
121
|
-
:line=>
|
122
|
-
:method
|
123
|
-
{:object=>#<Test:
|
152
|
+
:line=>50,
|
153
|
+
:method=>:and_another_test_in_another_object},
|
154
|
+
{:object=>#<Test:0x0000010102a400>,
|
124
155
|
:file=>"sender_test.rb",
|
125
156
|
:line=>21,
|
126
|
-
:method
|
157
|
+
:method=>:another_test}]
|
127
158
|
These should be true:
|
128
159
|
true
|
129
160
|
true
|
data/VERSION.rdoc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.3
|
data/ext/sender/rb_Global.c
CHANGED
@@ -43,16 +43,38 @@ VALUE rb_RPRuby_Sender___sender__() {
|
|
43
43
|
VALUE rb_backtrace_limit = INT2FIX( 3 );
|
44
44
|
|
45
45
|
VALUE rb_backtrace_array = rb_RPRuby_Sender_Kernel_backtrace( 1,
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
& rb_backtrace_limit,
|
47
|
+
rb_mKernel );
|
48
|
+
|
49
|
+
int c_backtrace_index = 1;
|
50
|
+
|
51
|
+
VALUE rb_backtrace_frame_hash = rb_ary_entry( rb_backtrace_array, c_backtrace_index );
|
50
52
|
|
51
53
|
VALUE rb_caller = rb_hash_aref( rb_backtrace_frame_hash,
|
52
54
|
ID2SYM( rb_intern( "method" ) ) );
|
53
55
|
|
56
|
+
// if we get :initialize as our caller and our __method__ is :initialize, we need to go up the chain
|
57
|
+
// until our caller is no longer :initialize or :new
|
58
|
+
while ( rb_caller == ID2SYM( rb_intern( "initialize" ) ) ) {
|
59
|
+
c_backtrace_index++;
|
60
|
+
rb_backtrace_frame_hash = rb_ary_entry( rb_backtrace_array, c_backtrace_index );
|
61
|
+
rb_caller = rb_hash_aref( rb_backtrace_frame_hash,
|
62
|
+
ID2SYM( rb_intern( "method" ) ) );
|
63
|
+
|
64
|
+
// we have one parent past our current method; if that is also :initialize, get the whole backtrace
|
65
|
+
if ( c_backtrace_index == 2 ) {
|
66
|
+
rb_backtrace_array = rb_RPRuby_Sender_Kernel_backtrace( 0, NULL, rb_mKernel );
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
// if we get "new" as our caller we need to get the next level, as we are in :initialize
|
71
|
+
// and want to know what called :new
|
72
|
+
//
|
73
|
+
// since we might have had to go up the chain from :initialize through parents before getting here we
|
74
|
+
// want to use a separate if statement
|
54
75
|
if ( rb_caller == ID2SYM( rb_intern( "new" ) ) ) {
|
55
|
-
|
76
|
+
c_backtrace_index++;
|
77
|
+
rb_backtrace_frame_hash = rb_ary_entry( rb_backtrace_array, c_backtrace_index );
|
56
78
|
}
|
57
79
|
|
58
80
|
VALUE rb_sender = rb_hash_aref( rb_backtrace_frame_hash,
|
@@ -82,17 +104,43 @@ VALUE rb_RPRuby_Sender___caller__() {
|
|
82
104
|
VALUE rb_backtrace_limit = INT2FIX( 3 );
|
83
105
|
|
84
106
|
VALUE rb_backtrace_array = rb_RPRuby_Sender_Kernel_backtrace( 1,
|
85
|
-
|
86
|
-
|
107
|
+
& rb_backtrace_limit,
|
108
|
+
rb_mKernel );
|
109
|
+
|
110
|
+
int c_backtrace_index = 1;
|
87
111
|
|
88
|
-
VALUE rb_backtrace_frame_hash = rb_ary_entry( rb_backtrace_array,
|
112
|
+
VALUE rb_backtrace_frame_hash = rb_ary_entry( rb_backtrace_array, c_backtrace_index );
|
89
113
|
|
90
114
|
VALUE rb_caller = rb_hash_aref( rb_backtrace_frame_hash,
|
91
|
-
|
115
|
+
ID2SYM( rb_intern( "method" ) ) );
|
92
116
|
|
93
|
-
|
94
|
-
|
117
|
+
// we want to compare our caller as we go up the chain to our first caller to deal with super methods
|
118
|
+
// we have a symbol so no cloning is necessary (or appropriate)
|
119
|
+
VALUE rb_first_caller = rb_hash_aref( rb_ary_entry( rb_backtrace_array, 0 ),
|
120
|
+
ID2SYM( rb_intern( "method" ) ) );
|
121
|
+
|
122
|
+
// if we get :initialize as our caller and our __method__ is :initialize, we need to go up the chain
|
123
|
+
// until our caller is no longer :initialize or :new
|
124
|
+
while ( rb_caller == rb_first_caller ) {
|
125
|
+
c_backtrace_index++;
|
126
|
+
rb_backtrace_frame_hash = rb_ary_entry( rb_backtrace_array, c_backtrace_index );
|
127
|
+
rb_caller = rb_hash_aref( rb_backtrace_frame_hash,
|
128
|
+
ID2SYM( rb_intern( "method" ) ) );
|
95
129
|
|
130
|
+
// we have one parent past our current method; if that is also :initialize, get the whole backtrace
|
131
|
+
if ( c_backtrace_index == 2 ) {
|
132
|
+
rb_backtrace_array = rb_RPRuby_Sender_Kernel_backtrace( 0, NULL, rb_mKernel );
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
// if we get "new" as our caller we need to get the next level, as we are in :initialize
|
137
|
+
// and want to know what called :new
|
138
|
+
//
|
139
|
+
// since we might have had to go up the chain from :initialize through parents before getting here we
|
140
|
+
// want to use a separate if statement
|
141
|
+
if ( rb_caller == ID2SYM( rb_intern( "new" ) ) ) {
|
142
|
+
c_backtrace_index++;
|
143
|
+
rb_backtrace_frame_hash = rb_ary_entry( rb_backtrace_array, c_backtrace_index );
|
96
144
|
rb_caller = rb_hash_aref( rb_backtrace_frame_hash,
|
97
145
|
ID2SYM( rb_intern( "method" ) ) );
|
98
146
|
}
|
data/lib/VERSION.rdoc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.3
|
data/lib/sender/sender.bundle
CHANGED
Binary file
|
data/sender.gemspec
CHANGED
metadata
CHANGED