lib/socrates/adapters/memory_adapter.rb in socrates-0.1.1 vs lib/socrates/adapters/memory_adapter.rb in socrates-0.1.2
- old
+ new
@@ -1,29 +1,46 @@
-class MemoryAdapter
- CLIENT_ID = "MEMORY"
+module Socrates
+ module Adapters
+ class MemoryAdapter
+ CLIENT_ID = "MEMORY"
- attr_reader :history, :dms
+ attr_reader :history, :dms
+ attr_accessor :email, :users
- def initialize
- @history = []
- @dms = {}
- end
+ def initialize
+ @history = []
+ @dms = Hash.new { |hash, key| hash[key] = [] }
+ @users = []
+ end
- def client_id_from_context(_context)
- CLIENT_ID
- end
+ def client_id_from_context(_context)
+ CLIENT_ID
+ end
- def send_message(message, *)
- @history << message
- end
+ def send_message(message, *)
+ @history << message
+ end
- def send_direct_message(message, user, *)
- user = user.id if user.respond_to?(:id)
+ def send_direct_message(message, user, *)
+ user = user.id if user.respond_to?(:id)
- @dms[user] = [] unless @dms.key?(user)
- @dms[user] << message
- end
+ @dms[user] << message
+ end
- def last_message
- @history.last
+ def last_message
+ @history.last
+ end
+
+ def add_user(id: nil, name: nil, first: nil, last: nil, email: nil)
+ users << User.new(id, name, Profile.new(first, last, email))
+ end
+
+ def users_list
+ Response.new(users)
+ end
+
+ def lookup_email(*)
+ email
+ end
+ end
end
end