Class: Rake::Subproject::Client::Port
- Inherits:
-
Object
- Object
- Rake::Subproject::Client::Port
- Defined in:
- lib/rake/subproject/client/port.rb
Overview
:nodoc: all
Constant Summary collapse
- DELIMITER =
"\0"
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(io, name = nil) ⇒ Port
constructor
A new instance of Port.
- #inspect ⇒ Object
- #read ⇒ Object
- #write(object) ⇒ Object
Constructor Details
#initialize(io, name = nil) ⇒ Port
Returns a new instance of Port.
15 16 17 18 19 |
# File 'lib/rake/subproject/client/port.rb', line 15 def initialize(io, name = nil) fail ArgumentError, "Requires an IO object" unless io.kind_of?(IO) @io = io self.name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/rake/subproject/client/port.rb', line 4 def name @name end |
Class Method Details
.open(fd, option) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/rake/subproject/client/port.rb', line 6 def self.open(fd, option) return unless block_given? IO.open(fd, option) do |io| yield port = self.new(io, "server") end end |
Instance Method Details
#close ⇒ Object
39 40 41 42 |
# File 'lib/rake/subproject/client/port.rb', line 39 def close log "closing #{self.inspect}" @io.close end |
#closed? ⇒ Boolean
44 45 46 |
# File 'lib/rake/subproject/client/port.rb', line 44 def closed? @io.closed? end |
#inspect ⇒ Object
21 22 23 |
# File 'lib/rake/subproject/client/port.rb', line 21 def inspect "Port(#{self.name || @io.fileno})" end |
#read ⇒ Object
25 26 27 28 29 30 |
# File 'lib/rake/subproject/client/port.rb', line 25 def read log "reading #{self.inspect}..." = @io.readline(DELIMITER).chomp(DELIMITER) log "... #{self.inspect} received: #{}" ::JSON.parse() end |
#write(object) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/rake/subproject/client/port.rb', line 32 def write(object) = ::JSON.generate(object) @io.print(+DELIMITER) @io.flush log "#{self.inspect} wrote: #{}" end |