Class: Socrates::Adapters::Memory
- Inherits:
-
Object
- Object
- Socrates::Adapters::Memory
- Includes:
- Adapter, StubUserDirectory
- Defined in:
- lib/socrates/adapters/memory.rb
Constant Summary collapse
- CLIENT_ID =
"MEMORY"
- CHANNEL =
"C1"
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
Attributes included from StubUserDirectory
Instance Method Summary collapse
- #channel_from(context: nil, user: nil) ⇒ Object
- #client_id_from(context: nil, user: nil) ⇒ Object
- #dms(user) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #last_dm(user) ⇒ Object
- #last_msg ⇒ Object
-
#msgs ⇒ Object
Methods for fetching messages and dms in specs…
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 ⇒ Memory
Returns a new instance of Memory.
16 17 18 19 |
# File 'lib/socrates/adapters/memory.rb', line 16 def initialize super() @history = Hash.new { |hash, key| hash[key] = [] } end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
14 15 16 |
# File 'lib/socrates/adapters/memory.rb', line 14 def client_id @client_id end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
13 14 15 |
# File 'lib/socrates/adapters/memory.rb', line 13 def history @history end |
Instance Method Details
#channel_from(context: nil, user: nil) ⇒ Object
27 28 29 30 31 |
# File 'lib/socrates/adapters/memory.rb', line 27 def channel_from(context: nil, user: nil) raise ArgumentError, "Must provide one of :context or :user" if context.nil? && user.nil? user.nil? ? CHANNEL : users_channel(user) end |
#client_id_from(context: nil, user: nil) ⇒ Object
21 22 23 24 25 |
# File 'lib/socrates/adapters/memory.rb', line 21 def client_id_from(context: nil, user: nil) raise ArgumentError, "Must provide one of :context or :user" if context.nil? && user.nil? @client_id || CLIENT_ID end |
#dms(user) ⇒ Object
45 46 47 |
# File 'lib/socrates/adapters/memory.rb', line 45 def dms(user) @history[users_channel(user)] end |
#last_dm(user) ⇒ Object
49 50 51 |
# File 'lib/socrates/adapters/memory.rb', line 49 def last_dm(user) dms(user)[-1] end |
#last_msg ⇒ Object
41 42 43 |
# File 'lib/socrates/adapters/memory.rb', line 41 def last_msg msgs[-1] end |
#msgs ⇒ Object
Methods for fetching messages and dms in specs…
37 38 39 |
# File 'lib/socrates/adapters/memory.rb', line 37 def msgs @history[CHANNEL] end |