Sha256: 4c1cb579afc4a5f45c269ccea3ecc09dcc2193baa7b76cecd821138e12e725a7

Contents?: true

Size: 943 Bytes

Versions: 3

Compression:

Stored size: 943 Bytes

Contents

require "socrates/adapters/stubs"

module Socrates
  module Adapters
    class Memory
      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

3 entries across 3 versions & 1 rubygems

Version Path
socrates-0.1.10 lib/socrates/adapters/memory.rb
socrates-0.1.9 lib/socrates/adapters/memory.rb
socrates-0.1.8 lib/socrates/adapters/memory.rb