em-stdout 0.0.1

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.
@@ -0,0 +1,51 @@
1
+ require 'eventmachine'
2
+
3
+ module EventMachine
4
+ class << self
5
+ def split_stdout
6
+ stdout = nil
7
+ EM.next_tick do
8
+ stdout, read, write = STDOUT.clone, *IO.pipe
9
+ EM.attach(read, Stdout) do |connection|
10
+ connection.stdout = stdout
11
+ yield connection if block_given?
12
+ end
13
+ STDOUT.reopen(write)
14
+ end
15
+ sleep(0.01) until stdout
16
+ stdout
17
+ end
18
+ end
19
+
20
+ class Stdout < EventMachine::Connection
21
+ class << self
22
+ def output
23
+ defined?(@@output) ? @@output : @@output = true
24
+ end
25
+
26
+ def output=(output)
27
+ @@output = output
28
+ end
29
+ end
30
+
31
+ attr_accessor :stdout
32
+
33
+ def callback(&block)
34
+ @callback = block
35
+ end
36
+
37
+ def on_close(&block)
38
+ @on_close = block
39
+ end
40
+
41
+ def receive_data(data)
42
+ stdout.print(data) if self.class.output
43
+ @callback.call(data) if @callback
44
+ end
45
+
46
+ def unbind
47
+ STDOUT.reopen(stdout)
48
+ @on_close.call if @on_close
49
+ end
50
+ end
51
+ end
@@ -0,0 +1 @@
1
+ require 'em/stdout'
@@ -0,0 +1,3 @@
1
+ module EmStdout
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-stdout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sven Fuchs
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-06-07 00:00:00.000000000 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+ description: ! '[description]'
16
+ email: svenfuchs@artweb-design.de
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/em/stdout.rb
22
+ - lib/em_stdout.rb
23
+ - lib/em_stdout/version.rb
24
+ has_rdoc: true
25
+ homepage: http://github.com/svenfuchs/em-stdout
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project: ! '[none]'
45
+ rubygems_version: 1.6.2
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: ! '[summary]'
49
+ test_files: []