Module: Socrates::Adapters::Adapter
Instance Method Summary collapse
- #channel_from(context: nil, user: nil) ⇒ Object
-
#client_id_from(context: nil, user: nil) ⇒ Object
Many of the methods in the Adapter module serve as an interface for Adapter implementations to implement.
- #flush_session(session, channel: nil) ⇒ Object
- #lookup_email ⇒ Object
- #lookup_user(email:) ⇒ Object
- #queue_direct_message(session, message, recipient) ⇒ Object
- #queue_message(session, message, send_now: false) ⇒ Object
- #send_message(channel, message) ⇒ Object
- #user_from(context:) ⇒ Object
- #users(include_deleted: false, include_bots: false) ⇒ Object
Instance Method Details
#channel_from(context: nil, user: nil) ⇒ Object
13 14 15 |
# File 'lib/socrates/adapters/adapter.rb', line 13 def channel_from(context: nil, user: nil) raise NotImplementedError end |
#client_id_from(context: nil, user: nil) ⇒ Object
Many of the methods in the Adapter module serve as an interface for Adapter implementations to implement. We want to serve as an example, even if we don’t provide implementations here.
9 10 11 |
# File 'lib/socrates/adapters/adapter.rb', line 9 def client_id_from(context: nil, user: nil) raise NotImplementedError end |
#flush_session(session, channel: nil) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/socrates/adapters/adapter.rb', line 34 def flush_session(session, channel: nil) session..select { |c, _| channel.nil? || channel == c }.each do |c, | (c, .join("\n\n")) .clear end end |
#lookup_email ⇒ Object
57 58 59 |
# File 'lib/socrates/adapters/adapter.rb', line 57 def lookup_email(*) raise NotImplementedError end |
#lookup_user(email:) ⇒ Object
53 54 55 |
# File 'lib/socrates/adapters/adapter.rb', line 53 def lookup_user(email:) users.members.find { |user| email == user.profile&.email } end |
#queue_direct_message(session, message, recipient) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/socrates/adapters/adapter.rb', line 25 def (session, , recipient) raise ArgumentError, "recipient is required" unless recipient.present? raise ArgumentError, "recipient.id is required" unless recipient.id.present? dm_channel = channel_from(user: recipient) session.[dm_channel] << end |
#queue_message(session, message, send_now: false) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/socrates/adapters/adapter.rb', line 17 def (session, , send_now: false) raise ArgumentError, "session is required" unless session.present? raise ArgumentError, "session.channel is required" unless session.channel.present? session.[session.channel] << flush_session(session, channel: session.channel) if send_now end |
#send_message(channel, message) ⇒ Object
41 42 43 |
# File 'lib/socrates/adapters/adapter.rb', line 41 def (channel, ) raise NotImplementedError end |
#user_from(context:) ⇒ Object
49 50 51 |
# File 'lib/socrates/adapters/adapter.rb', line 49 def user_from(context:) raise NotImplementedError end |
#users(include_deleted: false, include_bots: false) ⇒ Object
45 46 47 |
# File 'lib/socrates/adapters/adapter.rb', line 45 def users(include_deleted: false, include_bots: false) raise NotImplementedError end |