Class: HomuraRuntimeIO

Inherits:
Object
  • Object
show all
Defined in:
lib/homura/runtime.rb

Overview


  1. stdout / stderr → console.log / console.error


Instance Method Summary collapse

Constructor Details

#initialize(channel) ⇒ HomuraRuntimeIO

Returns a new instance of HomuraRuntimeIO.



39
40
41
42
# File 'lib/homura/runtime.rb', line 39

def initialize(channel)
  @channel = channel # 'log' or 'error'
  @buffer = ""
end

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/homura/runtime.rb', line 96

def closed?
  false
end

#flushObject



78
79
80
81
82
83
# File 'lib/homura/runtime.rb', line 78

def flush
  return self if @buffer.empty?
  emit(@buffer)
  @buffer = ""
  self
end

#isattyObject



93
94
95
# File 'lib/homura/runtime.rb', line 93

def isatty
  false
end


72
73
74
75
76
# File 'lib/homura/runtime.rb', line 72

def print(*args)
  args.each { |a| @buffer = @buffer + a.to_s }
  flush_lines
  nil
end

#puts(*args) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/homura/runtime.rb', line 55

def puts(*args)
  if args.empty?
    emit("")
    return nil
  end
  args.each do |arg|
    if arg.is_a?(Array)
      puts(*arg)
      next
    end
    line = arg.to_s
    @buffer = @buffer + (line.end_with?("\n") ? line : line + "\n")
  end
  flush_lines
  nil
end

#syncObject



85
86
87
# File 'lib/homura/runtime.rb', line 85

def sync
  true
end

#sync=(_) ⇒ Object



88
89
# File 'lib/homura/runtime.rb', line 88

def sync=(_)
end

#tty?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/homura/runtime.rb', line 90

def tty?
  false
end

#write(*args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/homura/runtime.rb', line 44

def write(*args)
  written = 0
  args.each do |arg|
    str = arg.to_s
    @buffer = @buffer + str
    written += str.length
  end
  flush_lines
  written
end