controllers/session.rb in nano-bots-0.0.2 vs controllers/session.rb in nano-bots-0.0.3
- old
+ new
@@ -10,16 +10,17 @@
module NanoBot
module Controllers
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
@state = { history: [] }
else
@@ -28,11 +29,11 @@
)
@state = load_state
end
end
- def debug
+ def state
pp({
state: {
path: @state_path,
content: @state
}
@@ -65,21 +66,21 @@
input = { behavior:, history: @state[:history] }
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
provider && interface
end
def process(input, mode:)
interface = Logic::Helpers::Hash.fetch(@cartridge, [:interfaces, mode.to_sym]) || {}
- streaming = stream(interface)
+ streaming = streaming(interface)
input[:interface] = interface
updated_at = Time.now
@@ -103,14 +104,14 @@
store_state! unless @stateless
end
def flush
- @output.flush
+ @stream.flush
end
def print(content)
- @output.write(content)
+ @stream.write(content)
end
end
end
end