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
43
# File 'lib/homura/runtime.rb', line 39

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

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/homura/runtime.rb', line 105

def closed?
  false
end

#flushObject



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

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

#isattyObject



101
102
103
# File 'lib/homura/runtime.rb', line 101

def isatty
  false
end


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

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

#puts(*args) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/homura/runtime.rb', line 57

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



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

def sync
  true
end

#sync=(_) ⇒ Object



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

def sync=(_)
end

#tty?Boolean

Returns:

  • (Boolean)


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

def tty?
  false
end

#write(*args) ⇒ Object



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

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

  flush_lines
  written
end