Class: RiderServer::Services::IO

Inherits:
Object
  • Object
show all
Defined in:
lib/rider_server/services/capture_io.rb

Instance Method Summary collapse

Constructor Details

#initialize(io, stream_name) ⇒ IO

Returns a new instance of IO.



86
87
88
89
# File 'lib/rider_server/services/capture_io.rb', line 86

def initialize(io, stream_name)
  @stream_name = stream_name
  @io = io
end

Instance Method Details

#<<(obj) ⇒ Object



107
108
109
110
# File 'lib/rider_server/services/capture_io.rb', line 107

def <<(obj)
  write(obj.to_s)
  self
end


112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/rider_server/services/capture_io.rb', line 112

def print(*args)
  if args.length == 0
    write($_)
  else
    args.each_with_index do |arg, index|
      write(arg.to_s)
      if $, && index < args.length - 1
        write($,)
      end
    end
    nil
  end
end

#printf(format_string, *args) ⇒ Object



126
127
128
129
# File 'lib/rider_server/services/capture_io.rb', line 126

def printf(format_string, *args)
  write(sprintf(format_string, *args))
  nil
end

#putc(obj) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/rider_server/services/capture_io.rb', line 131

def putc(obj)
  if obj.is_a?(String)
    write(obj[0])
  else
    # The real version triggers a "TypeError: no implicit
    # conversion of IO into Integer", when called on objects that
    # are not numbers or strings and can't be coerced to a number.
    write(obj.to_int.chr)
  end
  obj
end

#puts(*args) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/rider_server/services/capture_io.rb', line 143

def puts(*args)
  args.each do |arg|
    if arg.is_a?(Array)
      arg.each do |a|
        write(a.to_s, "\n")
      end
    else
      write(arg.to_s, "\n")
    end
  end

  write("\n") if args.length == 0
  nil
end

#pwrite(string, offset) ⇒ Object

Raises:

  • (NotImplementedError)


162
163
164
# File 'lib/rider_server/services/capture_io.rb', line 162

def pwrite(string, offset)
  raise NotImplementedError
end

#syswrite(string) ⇒ Object



102
103
104
105
# File 'lib/rider_server/services/capture_io.rb', line 102

def syswrite(string)
  Services::CaptureIO.nwrite(@stream_name, string.to_s)
  @io.syswrite(string)
end

#to_ioObject



158
159
160
# File 'lib/rider_server/services/capture_io.rb', line 158

def to_io
  self
end

#write(*string) ⇒ Object



91
92
93
94
95
# File 'lib/rider_server/services/capture_io.rb', line 91

def write(*string)
  strings = string.map(&:to_s)
  Services::CaptureIO.nwrite(@stream_name, *strings)
  @io.write(*strings)
end

#write_nonblock(string, **kwargs) ⇒ Object



97
98
99
100
# File 'lib/rider_server/services/capture_io.rb', line 97

def write_nonblock(string, **kwargs)
  Services::CaptureIO.nwrite(@stream_name, string.to_s)
  @io.write_nonblock(strings, **kwargs)
end