Sha256: cc2bc58918d53deda76956a73b68a60b14874698225a3dde153e8c5c6de422de

Contents?: true

Size: 915 Bytes

Versions: 1

Compression:

Stored size: 915 Bytes

Contents

module Socrates
  module Adapters
    class MemoryAdapter
      CLIENT_ID = "MEMORY"

      attr_reader :history, :dms
      attr_accessor :email, :users

      def initialize
        @history = []
        @dms     = Hash.new { |hash, key| hash[key] = [] }
        @users   = []
      end

      def client_id_from_context(_context)
        CLIENT_ID
      end

      def send_message(message, *)
        @history << message
      end

      def send_direct_message(message, user, *)
        user = user.id if user.respond_to?(:id)

        @dms[user] << message
      end

      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
socrates-0.1.7 lib/socrates/adapters/memory_adapter.rb