pusher/pusher-http-ruby

Pusher.cluster delegates to Pusher::Client#cluster which is not defined

nertzy opened this issue · 5 comments

See

def_delegators :default_client, :authentication_token, :url, :cluster
where Pusher.cluster is delegating to Pusher::Client#cluster.

Notice that Pusher::Client#cluster is not defined.

irb(main):009:0> Pusher.client
Traceback (most recent call last):
        2: from (irb):5
        1: from (irb):6:in `rescue in irb_binding'
NoMethodError (undefined method `client' for Pusher:Module)

Here's my workaround for now:

require "pusher/client"

module Pusher
  class Client
    # Pusher::Client#cluster is not defined, even through Pusher.cluster
    # delegates to it.
    #
    # See https://github.com/pusher/pusher-http-ruby/issues/158
    def cluster
      /api-([^.]*).pusher.com/.match(host)[1]
    end
  end
end
stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you'd like this issue to stay open please leave a comment indicating how this issue is affecting you. Thank you.

Sorry about that, I just enabled stalebot, but I am looking into this.

hi @nertzy , sorry for the late reply. After looking a bit into this, I no longer consider this a bug. Client.cluster is indeed defined, but it is a setter, meaning you can only use it as an alternative way to configure the SDK, as described in the README.

You cannot use this to get the cluster, which is intended. I gave a more detailed explanation about this in the original issue (#135) which also describes the use case.

You (and anyone else) are obviously welcome to use the workaround posted here, but it can't work in the general case because we allow the user to specify any arbitrary host.

@elverkilde Thanks for the update, and sorry for my late response as well.

If there is not supposed to be a method for fetching the client, then I think that a delegator should not be defined.

This line still defines the delegating method:

def_delegators :default_client, :authentication_token, :url, :cluster

:cluster should be removed from that line so that there is no longer a Pusher.cluster method that raises when called.

Note that it's safe to remove the getter delegator because the setter is defined on the next line:

def_delegators :default_client, :encrypted=, :url=, :cluster=