Class: Async::Matrix::Api::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/async/matrix/api.rb

Overview

Gateway produces Chain instances bound to a specific Client. Each call to a method on the Gateway starts a new chain.

Instance Method Summary collapse

Constructor Details

#initialize(client, prefix: %w[_matrix client v3])) ⇒ Gateway

Returns a new instance of Gateway.



44
45
46
47
# File 'lib/async/matrix/api.rb', line 44

def initialize(client, prefix: %w[_matrix client v3])
  @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.



56
57
58
59
60
61
62
# File 'lib/async/matrix/api.rb', line 56

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

#chainObject

Start a fresh chain. Every method call on the gateway creates a new chain so chains are never reused.



51
52
53
# File 'lib/async/matrix/api.rb', line 51

def chain
  Chain.new(client: @client, path_tree: Api.path_tree, prefix: @prefix)
end

#inspectObject



68
69
70
# File 'lib/async/matrix/api.rb', line 68

def inspect
  "#<#{self.class} prefix=/#{@prefix.join("/")}>"
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/async/matrix/api.rb', line 64

def respond_to_missing?(name, include_private = false)
  !name.start_with?("to_") || super
end