summaryrefslogtreecommitdiff
path: root/controllers/session.rb
diff options
context:
space:
mode:
authoricebaker <113217272+icebaker@users.noreply.github.com>2023-05-13 11:30:12 -0300
committerGitHub <noreply@github.com>2023-05-13 11:30:12 -0300
commitf52b8f3c73d53d4fe6faa1d4670194d3c6c6d992 (patch)
tree02aac93f5d618c2965973b2390de3adabf21be25 /controllers/session.rb
parent805e5073117bc717f46da0fa7f8ab628b4fa2a7d (diff)
parent680d55dbea3c8aec5049bd387aadaf31a443c8fd (diff)
Merge pull request #1 from icebaker/ib-streams
Improving Streams
Diffstat (limited to 'controllers/session.rb')
-rw-r--r--controllers/session.rb17
1 files changed, 9 insertions, 8 deletions
diff --git a/controllers/session.rb b/controllers/session.rb
index ff3b8ad..afaca18 100644
--- a/controllers/session.rb
+++ b/controllers/session.rb
@@ -12,12 +12,13 @@ module NanoBot
STREAM_TIMEOUT_IN_SECONDS = 5
class Session
- def initialize(provider:, cartridge:, state: nil)
+ attr_accessor :stream
+
+ def initialize(provider:, cartridge:, state: nil, stream: $stdout)
+ @stream = stream
@provider = provider
@cartridge = cartridge
- @output = $stdout
-
@stateless = state.nil? || state.strip == '-' || state.strip.empty?
if @stateless
@@ -30,7 +31,7 @@ module NanoBot
end
end
- def debug
+ def state
pp({
state: {
path: @state_path,
@@ -67,7 +68,7 @@ module NanoBot
process(input, mode:)
end
- def stream(interface)
+ def streaming(interface)
provider = @provider.settings.key?(:stream) ? @provider.settings[:stream] : true
interface = interface.key?(:stream) ? interface[:stream] : true
@@ -77,7 +78,7 @@ module NanoBot
def process(input, mode:)
interface = Logic::Helpers::Hash.fetch(@cartridge, [:interfaces, mode.to_sym]) || {}
- streaming = stream(interface)
+ streaming = streaming(interface)
input[:interface] = interface
@@ -105,11 +106,11 @@ module NanoBot
end
def flush
- @output.flush
+ @stream.flush
end
def print(content)
- @output.write(content)
+ @stream.write(content)
end
end
end