class BotPlatform::Storage::MemoryStorage
Attributes
data[RW]
locker[RW]
Public Class Methods
new()
click to toggle source
# File lib/bot_platform/storage/memory_storage.rb, line 13 def initialize @locker = Mutex::new @data = {} end
Public Instance Methods
getState(context)
click to toggle source
# File lib/bot_platform/storage/memory_storage.rb, line 39 def getState(context) user_id = context.from[:user_id] room_id = context.from[:room_id] || "" # FIXME: room_id appear and disappear #key = "#{user_id}@#{room_id}" key = "#{user_id}".intern @data[key] = ConversationState.new(key) if @data[key].nil? return @data[key] end
read(keys)
click to toggle source
# File lib/bot_platform/storage/memory_storage.rb, line 18 def read(keys) new_hash = {} @locker.synchronize do keys.each do |key| if @data.key?(key) k = key.to_sym new_hash[k] = @data[k] end end end return new_hash end
write(changes)
click to toggle source
# File lib/bot_platform/storage/memory_storage.rb, line 31 def write(changes) @locker.synchronize do changes.each do |change| @data[change.key.to_sym] = change.value end end end