Class: Socrates::Adapters::Console

Inherits:
Object
  • Object
show all
Includes:
Adapter, StubUserDirectory
Defined in:
lib/socrates/adapters/console.rb

Constant Summary collapse

CLIENT_ID =
"CONSOLE"

Instance Attribute Summary

Attributes included from StubUserDirectory

#default_user

Instance Method Summary collapse

Methods included from StubUserDirectory

#add_user, #lookup_email, #user_from, #users

Methods included from Adapter

#flush_session, #lookup_email, #lookup_user, #queue_direct_message, #queue_message, #user_from, #users

Constructor Details

#initialize(name: "@socrates") ⇒ Console

Returns a new instance of Console.



12
13
14
15
# File 'lib/socrates/adapters/console.rb', line 12

def initialize(name: "@socrates")
  super()
  @name = name
end

Instance Method Details

#channel_from(context: nil, user: nil) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/socrates/adapters/console.rb', line 23

def channel_from(context: nil, user: nil)
  raise ArgumentError, "Must provide one of :context or :user" if context.nil? && user.nil?

  if context&.fetch(:channel).present?
    context[:channel]
  elsif user.present?
    display_user(user)
  else
    "?"
  end
end

#client_id_from(context: nil, user: nil) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/socrates/adapters/console.rb', line 17

def client_id_from(context: nil, user: nil)
  raise ArgumentError, "Must provide one of :context or :user" if context.nil? && user.nil?

  CLIENT_ID
end