mhennemeyer-output_catcher 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +20 -0
  2. data/README +42 -0
  3. data/lib/output_catcher.rb +27 -0
  4. metadata +55 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Matthias Hennemeyer
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 ADDED
@@ -0,0 +1,42 @@
1
+ = OutputCatcher
2
+
3
+ by Matthias Hennemeyer <mhennemeyer@gmail.com>
4
+
5
+ == Introduction
6
+
7
+ OutputCatcher is available as a Rails plugin and as a gem.
8
+ It provides a way to capture the standard out($stdout) or standard error($stderr) of your code without pain
9
+ and suppresses the output of the 'err' or 'out' stream.
10
+
11
+
12
+ == Usage
13
+
14
+ OutputCatcher knows only two methods: .catch_err and .catch_out
15
+
16
+ To capture the stderr of your code:
17
+
18
+ err = OutputCatcher.catch_err do
19
+ $stderr << "error error"
20
+ end
21
+ err #=> "error error"
22
+
23
+
24
+ To capture the stdout of your code:
25
+
26
+ out = OutputCatcher.catch_out do
27
+ puts "Hello Hello"
28
+ end
29
+ out #=> "Hello Hello"
30
+
31
+ == INSTALL:
32
+ Rails:
33
+
34
+ $ ruby script/plugin install git://github.com/mhennemeyer/output_catcher.git
35
+
36
+ Gem:
37
+
38
+ $ gem install output_catcher --source=http://gems.github.com
39
+
40
+
41
+
42
+ Copyright (c) 2008 Matthias Hennemeyer, released under the MIT license
@@ -0,0 +1,27 @@
1
+ require 'stringio'
2
+
3
+ class OutputCatcher
4
+ class << self
5
+
6
+ def catch_io(post, &block)
7
+ original = eval("$std" + post)
8
+ fake = StringIO.new
9
+ eval("$std#{post} = fake")
10
+ begin
11
+ yield
12
+ ensure
13
+ eval("$std#{post} = original")
14
+ end
15
+ fake.string
16
+ end
17
+
18
+ def catch_out(&block)
19
+ catch_io("out", &block)
20
+ end
21
+
22
+ def catch_err(&block)
23
+ catch_io("err", &block)
24
+ end
25
+
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mhennemeyer-output_catcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthias Hennemeyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-14 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: OutputCatcher is available as a Rails plugin and as a gem. It provides a way to capture the standard out($stdout) or standard error($stderr) of your code without pain and suppresses the output of the 'err' or 'out' stream.
17
+ email: mhennemeyer@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - LICENSE
26
+ - README
27
+ - lib/output_catcher.rb
28
+ has_rdoc: false
29
+ homepage: http://workunitgroup.com/2008/5/26/output-catcher-for-ruby-and-rails
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.0.1
51
+ signing_key:
52
+ specification_version: 2
53
+ summary: OutputCatcher makes it easy to capture the $stderr and $stdout streams.
54
+ test_files: []
55
+