ruby-fifo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/ext/mkrf_conf.rb +24 -0
  2. data/lib/fifo.rb +78 -0
  3. metadata +65 -0
data/ext/mkrf_conf.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'rubygems/command'
3
+ require 'rubygems/dependency_installer'
4
+
5
+ begin
6
+ Gem::Command.build_args = ARGV
7
+ rescue NoMethodError
8
+ end
9
+
10
+ inst = Gem::DependencyInstaller.new
11
+
12
+ begin
13
+ if RUBY_PLATFORM =~ /mswin/
14
+ inst.install 'win32-pipe'
15
+ else
16
+ inst.install 'mkfifo'
17
+ end
18
+ rescue
19
+ exit(1)
20
+ end
21
+
22
+ f = File.open(File.join(File.dirname(__FILE__), 'Rakefile'), 'w')
23
+ f.write("task :default\n")
24
+ f.close
data/lib/fifo.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'forwardable'
2
+
3
+ begin
4
+ begin
5
+ require "win32/pipe"
6
+ $POSIX = false
7
+ rescue LoadError
8
+ require 'mkfifo'
9
+ $POSIX = true
10
+ end
11
+ rescue LoadError
12
+ raise LoadError, "No such file to load, please install 'win32/pipe' or 'mkfifo'"
13
+ end
14
+
15
+ class Fifo
16
+ include Forwardable
17
+
18
+ class ::File
19
+ alias :owrite :write
20
+ def write(*args)
21
+ owrite(*args)
22
+ flush
23
+ end
24
+ end
25
+
26
+ def initialize(file, perms = :r, mode = :nowait)
27
+ perms, mode = perms.to_s, mode.to_s
28
+ raise "Unknown perms." unless %w{r w}.include?(perms)
29
+ raise "Unknown mode." unless %w{wait nowait}.include?(mode)
30
+ perms, mode = perms.to_sym, mode.to_sym
31
+ if !$POSIX
32
+ include Win32
33
+
34
+ mode = {:wait => Pipe::WAIT, :nowait => Pipe::NOWAIT}[mode]
35
+ @pipe = perms == :r ? Pipe.new_server(file, mode) : Pipe.new_client(file)
36
+ @pipe.connect if perms == :r
37
+ else
38
+ if !File.exists?(file)
39
+ File.mkfifo(file)
40
+ File.chmod(0666, file)
41
+ end
42
+ @pipe = File.open(file, perms.to_s + {:wait => '', :nowait => '+'}[mode])
43
+ end
44
+
45
+ def_delegators :@pipe, :read, :write, :close
46
+ end
47
+
48
+ def print(*args)
49
+ args.each {|obj|
50
+ self.write obj.to_s
51
+ }
52
+ write $\
53
+ end
54
+
55
+ def puts(*args)
56
+ args.each {|obj|
57
+ self.write "#{obj.to_s.sub(/\n$/, '')}\n"
58
+ }
59
+ end
60
+
61
+ def getc
62
+ self.read(1)
63
+ end
64
+
65
+ def readline
66
+ str = ""
67
+ while ($_ = self.read(1)) != "\n"
68
+ str << $_
69
+ end
70
+ str << "\n"
71
+ end
72
+
73
+ def gets
74
+ str = ""
75
+ str << self.read(1) while !str.match(/#{Regexp.escape($/)}$/)
76
+ str
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-fifo
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - shura
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-16 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A library to use named pipe
22
+ email: shura1991@gmail.com
23
+ executables: []
24
+
25
+ extensions:
26
+ - ext/mkrf_conf.rb
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/fifo.rb
31
+ - ext/mkrf_conf.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/shurizzle/ruby-fifo
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.7
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: A library to use named pipe
64
+ test_files: []
65
+