irb_callbacks 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ F>����$�IAI��i�{a��'P�|���N �O"55ԟ _h�IsH�l� �\Ea�}wp����{v�?`Yԁ��� ��j�WqJ�hDM���{�)�������w�i`��Q�HG���i��WV�>���!������e1�����b�G�T�/���@a�'|��z�[�q���3C�p�ZE�ă�t:G�3v
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.1.0 / 2008-05-07
2
+
3
+ * Created!
4
+
data/Manifest.txt ADDED
@@ -0,0 +1,5 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/irb_callbacks.rb
data/README.txt ADDED
@@ -0,0 +1,97 @@
1
+ = irb_callbacks
2
+
3
+ * http://rubysideshow.rubyforge.org/irb_callbacks
4
+
5
+ == DESCRIPTION:
6
+
7
+ This gem adds callbacks to irb, intended for you to
8
+ override at your discretion.
9
+
10
+ == FEATURES:
11
+
12
+ irb's control flow looks like this:
13
+
14
+ loop:
15
+ * prompt
16
+ * eval
17
+ * output
18
+
19
+ This gem adds three callbacks to each phase.
20
+
21
+ module IRB:
22
+
23
+ * self.before_prompt
24
+ * self.around_prompt (call yield)
25
+ * self.after_prompt
26
+
27
+ * self.before_eval
28
+ * self.around_eval (call yield)
29
+ * self.after_eval
30
+
31
+ * self.before_output
32
+ * self.around_output (call yield)
33
+ * self.after_output
34
+
35
+ == SYNOPSIS:
36
+
37
+ # Here's my ~/.irbrc file (which is run at irb startup)
38
+
39
+ require 'rubygems'
40
+ require 'irb_callbacks'
41
+ require 'benchmark'
42
+
43
+ # This little snippet will time each command run via the console.
44
+
45
+ module IRB
46
+ def self.around_eval(&block)
47
+ @timing = Benchmark.realtime do
48
+ block.call
49
+ end
50
+ end
51
+
52
+ def self.after_output
53
+ puts "=> #{'%.3f' % @timing} seconds"
54
+ end
55
+ end
56
+
57
+ # And a sample irb session:
58
+
59
+ $ irb
60
+ irb(main):001:0> 1_000_000.times { |x| x + 1 }
61
+ => 1000000
62
+ => 0.330 seconds
63
+
64
+ == CAVEATS:
65
+
66
+ The three around_* callbacks all require you to call the
67
+ block that's passed in. If you don't do it, undefined
68
+ behavior may occur.
69
+
70
+ == INSTALL:
71
+
72
+ * sudo gem install irb_callbacks
73
+
74
+ == LICENSE:
75
+
76
+ (The MIT License)
77
+
78
+ Copyright (c) 2008 Mike Judge
79
+
80
+ Permission is hereby granted, free of charge, to any person obtaining
81
+ a copy of this software and associated documentation files (the
82
+ 'Software'), to deal in the Software without restriction, including
83
+ without limitation the rights to use, copy, modify, merge, publish,
84
+ distribute, sublicense, and/or sell copies of the Software, and to
85
+ permit persons to whom the Software is furnished to do so, subject to
86
+ the following conditions:
87
+
88
+ The above copyright notice and this permission notice shall be
89
+ included in all copies or substantial portions of the Software.
90
+
91
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
92
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
93
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
94
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
95
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
96
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
97
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/irb_callbacks.rb'
6
+
7
+ Hoe.new('irb_callbacks', IrbCallbacks::VERSION) do |p|
8
+ p.name = 'irb_callbacks'
9
+ p.rubyforge_name = 'rubysideshow'
10
+ p.author = 'Mike Judge'
11
+ p.email = 'mikelovesrobots@gmail.com'
12
+ p.summary = 'Adds three callbacks to the prompt, eval, and output phases of irb'
13
+ p.description = p.paragraphs_of('README.txt', 1..-1).join("\n\n")
14
+ end
15
+
16
+ # vim: syntax=Ruby
@@ -0,0 +1,289 @@
1
+ require 'irb'
2
+
3
+ #
4
+ # irb's control flow looks like this:
5
+ #
6
+ # loop:
7
+ #
8
+ # * prompt
9
+ # * eval
10
+ # * output
11
+ #
12
+ # This gem adds three callbacks to each
13
+ # phase, so you can override and provide
14
+ # your own functionality.
15
+ #
16
+ # module IRB:
17
+ #
18
+ # * self.before_prompt
19
+ # * self.around_prompt (call yield)
20
+ # * self.after_prompt
21
+ #
22
+ # * self.before_eval
23
+ # * self.around_eval (call yield)
24
+ # * self.after_eval
25
+ #
26
+ # * self.before_output
27
+ # * self.around_output (call yield)
28
+ # * self.after_output
29
+ #
30
+ # Some ideas to get you started:
31
+ #
32
+ # * automatic benchmarking
33
+ #
34
+ # (see the readme)
35
+ #
36
+ # * examine objectspace for leaks
37
+ #
38
+ # * tail the rails logs from irb
39
+ #
40
+ # You can automate irb to load up your changes
41
+ # each time you fire it up by adding the following
42
+ # to .irbrc in your home directory:
43
+ #
44
+ # require 'rubygems'
45
+ # require 'irb_callbacks'
46
+ #
47
+ # ... your code ...
48
+ #
49
+ # If you've got any requests or complaints,
50
+ # please e-mail mikelovesrobots@gmail.com.
51
+ #
52
+ class IrbCallbacks
53
+ VERSION = '0.1.0'
54
+ end
55
+
56
+ class RubyLex
57
+ alias original_lex lex
58
+
59
+ # Add before_prompt, after_prompt, and around_prompt callbacks
60
+ # without damaging original behavior.
61
+ def lex(*args, &block)
62
+ IRB::before_prompt
63
+ value = nil
64
+ IRB::around_prompt do
65
+ value = original_lex(*args, &block)
66
+ end
67
+ IRB::after_prompt
68
+ value
69
+ end
70
+ end
71
+
72
+ module IRB
73
+ class Irb
74
+ alias original_output_value output_value
75
+
76
+ # Add before_output, after_output, and around_output callbacks
77
+ # without damaging original behavior.
78
+ def output_value(*args, &block)
79
+ IRB::before_output
80
+ value = nil
81
+ IRB::around_output do
82
+ value = original_output_value(*args, &block)
83
+ end
84
+ IRB::after_output
85
+ value
86
+ end
87
+ end
88
+
89
+ class Context
90
+ alias original_evaluate evaluate
91
+ # Add before_eval, after_eval, and around_eval callbacks
92
+ # without damaging original behavior.
93
+ def evaluate(*args, &block)
94
+ IRB::before_eval
95
+ value = nil
96
+ IRB::around_eval do
97
+ value = original_evaluate(*args, &block)
98
+ end
99
+ IRB::after_eval
100
+ value
101
+ end
102
+ end
103
+ end
104
+
105
+ module IRB
106
+ # Called before prompting the user for each line of input. Example:
107
+ #
108
+ # module IRB
109
+ # def self.before_prompt
110
+ # puts "(before prompt)"
111
+ # end
112
+ # end
113
+ #
114
+ # $ irb
115
+ # (before prompt)
116
+ # irb(main):009:0> if true
117
+ # (before prompt)
118
+ # irb(main):010:1> false
119
+ # (before prompt)
120
+ # irb(main):011:1> end
121
+ # => false
122
+ #
123
+ def self.before_prompt
124
+ end
125
+
126
+ # Called after prompting the user for each line of input.
127
+ #
128
+ # module IRB
129
+ # def self.after_prompt
130
+ # puts "(after prompt)"
131
+ # end
132
+ # end
133
+ #
134
+ # $ irb
135
+ # irb(main):009:0> if true
136
+ # (after prompt)
137
+ # irb(main):010:1> false
138
+ # (after prompt)
139
+ # irb(main):011:1> end
140
+ # (after prompt)
141
+ # => false
142
+ #
143
+ def self.after_prompt
144
+ end
145
+
146
+ # Called immediately before the prompt. Choose when
147
+ # to call the prompt by calling yield. If you don't
148
+ # call yield, undefined bahavior will occur.
149
+ #
150
+ # module IRB
151
+ # def self.around_prompt
152
+ # puts "(Before prompt)"
153
+ # yield
154
+ # puts "(After prompt)"
155
+ # end
156
+ # end
157
+ #
158
+ # Sample session:
159
+ #
160
+ # $ irb
161
+ # (Before prompt)
162
+ # irb(main):001:0> true
163
+ # (After prompt)
164
+ # => true
165
+ #
166
+ def self.around_prompt
167
+ yield
168
+ end
169
+
170
+ # Called before evaling the user's input.
171
+ #
172
+ # module IRB
173
+ # def self.before_eval
174
+ # puts "(Before eval)"
175
+ # end
176
+ # end
177
+ #
178
+ # Sample session:
179
+ #
180
+ # $ irb
181
+ # irb(main):001:0> true
182
+ # (Before eval)
183
+ # => true
184
+ #
185
+ def self.before_eval
186
+ end
187
+
188
+ # Called after evaling the user's input.
189
+ #
190
+ # module IRB
191
+ # def self.after_eval
192
+ # puts "(After eval)"
193
+ # end
194
+ # end
195
+ #
196
+ # Sample session:
197
+ #
198
+ # $ irb
199
+ # irb(main):001:0> true
200
+ # (After eval)
201
+ # => true
202
+ #
203
+ #
204
+ def self.after_eval
205
+ end
206
+
207
+ # Called immediately before evaling the user's input.
208
+ # Choose when to fire off the eval by calling yield.
209
+ #
210
+ # module IRB
211
+ # def self.around_eval
212
+ # puts "(Before eval)"
213
+ # yield
214
+ # puts "(After eval)"
215
+ # end
216
+ # end
217
+ #
218
+ # Sample session:
219
+ #
220
+ # $ irb
221
+ # irb(main):001:0> true
222
+ # (Before eval)
223
+ # (After eval)
224
+ # => true
225
+ #
226
+ def self.around_eval
227
+ yield
228
+ end
229
+
230
+ # Called before outputing the result of the eval.
231
+ #
232
+ # module IRB
233
+ # def self.before_output
234
+ # puts "(Before output)"
235
+ # end
236
+ # end
237
+ #
238
+ # Sample session:
239
+ #
240
+ # $ irb
241
+ # irb(main):001:0> true
242
+ # (Before output)
243
+ # => true
244
+ #
245
+ def self.before_output
246
+ end
247
+
248
+ # Called after outputing the result of the eval.
249
+ #
250
+ # module IRB
251
+ # def self.after_output
252
+ # puts "(After output)"
253
+ # end
254
+ # end
255
+ #
256
+ # Sample session:
257
+ #
258
+ # $ irb
259
+ # irb(main):001:0> true
260
+ # => true
261
+ # (After output)
262
+ #
263
+ def self.after_output
264
+ end
265
+
266
+ # Called immediately before outputing the result of
267
+ # the eval. Choose when to output the results by
268
+ # calling yield.
269
+ #
270
+ # module IRB
271
+ # def self.around_output
272
+ # puts "(Before output)"
273
+ # yield
274
+ # puts "(After output)"
275
+ # end
276
+ # end
277
+ #
278
+ # Sample session:
279
+ #
280
+ # $ irb
281
+ # irb(main):001:0> true
282
+ # (Before output)
283
+ # => true
284
+ # (After output)
285
+ #
286
+ def self.around_output
287
+ yield
288
+ end
289
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irb_callbacks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Judge
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDQDCCAiigAwIBAgIBADANBgkqhkiG9w0BAQUFADBGMRgwFgYDVQQDDA9taWtl
14
+ bG92ZXNyb2JvdHMxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixk
15
+ ARkWA2NvbTAeFw0wODA0MTgwNTI4MjFaFw0wOTA0MTgwNTI4MjFaMEYxGDAWBgNV
16
+ BAMMD21pa2Vsb3Zlc3JvYm90czEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYK
17
+ CZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
18
+ 3VGB7/ek1pD/ZegUUH4jVotvO1z5G+vWZYwesXb8zdRLCHIXYNWHlPDcQKmB9vz3
19
+ ekn6BSrYEKR6Q9Ko6a2oWiadf+iz8WlD/FF2xwgoa2b7X3qMI0dowXWrHmCf19s8
20
+ +bynDIgsol3MbWJW+T5vVRjlRoN9sGCa+S8se7VNQ4pwMbddkvzcw62orbiJv9CK
21
+ HQAQnxU6v9x/wyRkBwD5blrhVHblA2YH+ZYc6lzMKHUGFrZ5E4rwG4UMnLUohg7I
22
+ y9KSfsy8QVl5RiOFDWAeCKxnRsCx4l2p8GetkEOCBFr9mKEJza3YBRQB6rWhy04H
23
+ 5N02HWQFzUmLwtfBMe6p1QIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
24
+ sDAdBgNVHQ4EFgQUekQzuTUI0pjbK++DouVgmNdjjvowDQYJKoZIhvcNAQEFBQAD
25
+ ggEBADfVkguKy9D2h+vvIAPmukjkZ+t0fuByLtamklmJ6HKmART5IH0oSfpJPNm2
26
+ EfGDvGwQ96W1ni1YfbRnP+cj3AOu03DfRWK52y1KYxIu4VcmZRKk8mCgJBJ3IVZf
27
+ 7GQkJ7gOjgj55DBfgdvwNQ4yXw+ACUTHAFkqwT05jAVse0swCiY9ruY60wUx+RTl
28
+ SivrkNPaARhL9KM3t70UdaqAIVrMqJva19xhLussfyvLeMnybSw2zE11N+9V5EPn
29
+ h2CoJJZOXHdgmDGaqY23v663f2FahHIRWtyCABJiU3YaUyFsd7zEtfjlCfufMvcp
30
+ aHG2UbipyooL1m/rJWEPIllGmbk=
31
+ -----END CERTIFICATE-----
32
+
33
+ date: 2008-05-13 00:00:00 -07:00
34
+ default_executable:
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: hoe
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.5.1
44
+ version:
45
+ description: "* http://rubysideshow.rubyforge.org/irb_callbacks == DESCRIPTION: This gem adds callbacks to irb, intended for you to override at your discretion. == FEATURES: irb's control flow looks like this: loop: * prompt * eval * output This gem adds three callbacks to each phase. module IRB: * self.before_prompt * self.around_prompt (call yield) * self.after_prompt * self.before_eval * self.around_eval (call yield) * self.after_eval * self.before_output * self.around_output (call yield) * self.after_output == SYNOPSIS: # Here's my ~/.irbrc file (which is run at irb startup) require 'rubygems' require 'irb_callbacks' require 'benchmark' # This little snippet will time each command run via the console. module IRB def self.around_eval(&block) @timing = Benchmark.realtime do block.call end end def self.after_output puts \"=> #{'%.3f' % @timing} seconds\" end end # And a sample irb session: $ irb irb(main):001:0> 1_000_000.times { |x| x + 1 } => 1000000 => 0.330 seconds == CAVEATS: The three around_* callbacks all require you to call the block that's passed in. If you don't do it, undefined behavior may occur. == INSTALL: * sudo gem install irb_callbacks == LICENSE: (The MIT License) Copyright (c) 2008 Mike Judge Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
46
+ email: mikelovesrobots@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - History.txt
53
+ - Manifest.txt
54
+ - README.txt
55
+ files:
56
+ - History.txt
57
+ - Manifest.txt
58
+ - README.txt
59
+ - Rakefile
60
+ - lib/irb_callbacks.rb
61
+ has_rdoc: true
62
+ homepage: http://rubysideshow.rubyforge.org/irb_callbacks
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --main
66
+ - README.txt
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: rubysideshow
84
+ rubygems_version: 1.1.1
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: Adds three callbacks to the prompt, eval, and output phases of irb
88
+ test_files: []
89
+
metadata.gz.sig ADDED
Binary file