Class: Async::Discord::Api::Gateway
- Inherits:
-
Object
- Object
- Async::Discord::Api::Gateway
- Defined in:
- lib/async/discord/api.rb
Overview
Gateway produces Chain instances bound to a specific Discord Client. Each call to a method on the Gateway starts a new chain.
Instance Method Summary collapse
-
#chain ⇒ Object
Start a fresh chain.
-
#initialize(client, prefix: %w[api v10])) ⇒ Gateway
constructor
A new instance of Gateway.
- #inspect ⇒ Object
-
#method_missing(name, *args, **kwargs, &block) ⇒ Object
Forward all unknown methods to a fresh chain, starting the path.
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(client, prefix: %w[api v10])) ⇒ Gateway
Returns a new instance of Gateway.
35 36 37 38 |
# File 'lib/async/discord/api.rb', line 35 def initialize(client, prefix: %w[api v10]) @client = client @prefix = prefix end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
Forward all unknown methods to a fresh chain, starting the path.
51 52 53 54 55 56 57 |
# File 'lib/async/discord/api.rb', line 51 def method_missing(name, *args, **kwargs, &block) if name.start_with?("to_") super else chain.__send__(name, *args, **kwargs, &block) end end |
Instance Method Details
#chain ⇒ Object
Start a fresh chain. Every method call on the gateway creates a new chain so chains are never reused.
42 43 44 45 46 47 48 |
# File 'lib/async/discord/api.rb', line 42 def chain Async::Matrix::Api::Chain.new( client: @client, path_tree: Api.path_tree, prefix: @prefix ) end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/async/discord/api.rb', line 63 def inspect "#<#{self.class} prefix=/#{@prefix.join("/")}>" end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
59 60 61 |
# File 'lib/async/discord/api.rb', line 59 def respond_to_missing?(name, include_private = false) !name.start_with?("to_") || super end |