Class: RailsConsoleAi::TeeIO

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_console_ai/executor.rb

Overview

Writes to two IO streams simultaneously

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(primary, secondary) ⇒ TeeIO

Returns a new instance of TeeIO.



9
10
11
12
# File 'lib/rails_console_ai/executor.rb', line 9

def initialize(primary, secondary)
  @primary = primary
  @secondary = secondary
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



39
40
41
# File 'lib/rails_console_ai/executor.rb', line 39

def method_missing(method, *args, &block)
  @primary.send(method, *args, &block)
end

Instance Attribute Details

#secondaryObject (readonly)

Returns the value of attribute secondary.



7
8
9
# File 'lib/rails_console_ai/executor.rb', line 7

def secondary
  @secondary
end

Instance Method Details

#flushObject



31
32
33
# File 'lib/rails_console_ai/executor.rb', line 31

def flush
  @primary.flush if @primary.respond_to?(:flush)
end


26
27
28
29
# File 'lib/rails_console_ai/executor.rb', line 26

def print(*args)
  @primary.print(*args)
  args.each { |a| @secondary.write(a.to_s) }
end

#puts(*args) ⇒ Object



19
20
21
22
23
24
# File 'lib/rails_console_ai/executor.rb', line 19

def puts(*args)
  @primary.puts(*args)
  # Capture what puts would output
  args.each { |a| @secondary.write("#{a}\n") }
  @secondary.write("\n") if args.empty?
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rails_console_ai/executor.rb', line 35

def respond_to_missing?(method, include_private = false)
  @primary.respond_to?(method, include_private) || super
end

#write(str) ⇒ Object



14
15
16
17
# File 'lib/rails_console_ai/executor.rb', line 14

def write(str)
  @primary.write(str)
  @secondary.write(str)
end