Class: RailsConsoleAi::PrefixedIO
- Inherits:
-
Object
- Object
- RailsConsoleAi::PrefixedIO
show all
- Defined in:
- lib/rails_console_ai/prefixed_io.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PrefixedIO.
3
4
5
|
# File 'lib/rails_console_ai/prefixed_io.rb', line 3
def initialize(io)
@io = io
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
46
47
48
|
# File 'lib/rails_console_ai/prefixed_io.rb', line 46
def method_missing(method, *args, &block)
@io.send(method, *args, &block)
end
|
Instance Method Details
#flush ⇒ Object
38
39
40
|
# File 'lib/rails_console_ai/prefixed_io.rb', line 38
def flush
@io.flush
end
|
#print(*args) ⇒ Object
34
35
36
|
# File 'lib/rails_console_ai/prefixed_io.rb', line 34
def print(*args)
@io.print(*args)
end
|
#puts(*args) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/rails_console_ai/prefixed_io.rb', line 17
def puts(*args)
prefix = Thread.current[:log_prefix]
if prefix
args = [""] if args.empty?
args.each do |a|
line = a.to_s
if line.strip.empty?
@io.write("\n")
else
@io.write("#{prefix} #{line}\n")
end
end
else
@io.puts(*args)
end
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
42
43
44
|
# File 'lib/rails_console_ai/prefixed_io.rb', line 42
def respond_to_missing?(method, include_private = false)
@io.respond_to?(method, include_private) || super
end
|
#write(str) ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/rails_console_ai/prefixed_io.rb', line 7
def write(str)
prefix = Thread.current[:log_prefix]
if prefix && str.is_a?(String) && !str.strip.empty?
prefixed = str.gsub(/^(?=.)/, "#{prefix} ")
@io.write(prefixed)
else
@io.write(str)
end
end
|