lib/socrates/adapters/memory.rb in socrates-0.1.16 vs lib/socrates/adapters/memory.rb in socrates-0.1.17
- old
+ new
@@ -1,10 +1,12 @@
+require "socrates/adapters/adapter"
require "socrates/adapters/stubs"
module Socrates
module Adapters
class Memory
+ include Socrates::Adapters::Adapter
include StubUserDirectory
CLIENT_ID = "MEMORY"
CHANNEL = "C1"
@@ -26,32 +28,10 @@
raise ArgumentError, "Must provide one of :context or :user" if context.nil? && user.nil?
user.nil? ? CHANNEL : users_channel(user)
end
- def send_message(session, message, send_now: false)
- raise ArgumentError, "Channel is required" unless session.channel.present?
-
- session.messages[session.channel] << message
- flush_session(session, channel: session.channel) if send_now
- end
-
- def send_direct_message(session, message, recipient)
- raise ArgumentError, "Recipient is required" unless recipient.present?
-
- im_channel = users_channel(recipient)
-
- session.messages[im_channel] << message
- end
-
- def flush_session(session, channel: nil) # TODO: Dry this up? Session? Included module?
- session.messages.select { |c, _| channel.nil? || channel == c }.each do |c, messages|
- _send_message(c, messages.join("\n\n"))
- messages.clear
- end
- end
-
#
# Methods for fetching messages and dms in specs...
#
def msgs
@@ -70,10 +50,10 @@
dms(user)[-1]
end
private
- def _send_message(channel, message) # TODO: Underscored name?
+ def send_message(channel, message)
@history[channel] << message
end
def users_channel(user)
user.respond_to?(:id) ? user.id : user