Sha256: 3dd74d2472496001a60503194b11d378f227402738f13c7d75c917bb3492839a

Contents?: true

Size: 1.66 KB

Versions: 19

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require "anycable/protos/rpc_pb"

require "anycable/rpc/handler"

# Extend some PB auto-generated classes
module AnyCable
  # Current RPC proto version (used for compatibility checks)
  PROTO_VERSION = "v1"
  SESSION_KEY = "_s_"

  # Add setters/getter for cstate field
  module WithConnectionState
    def initialize(session: nil, **other)
      if session
        other[:cstate] ||= {}
        other[:cstate][SESSION_KEY] = session
      end
      super(**other)
    end

    def session=(val)
      self.cstate = {} unless cstate
      state_ = cstate
      if state_
        state_[SESSION_KEY] = val
      end
    end

    def session
      state_ = cstate
      if state_
        state_[SESSION_KEY]
      end
    end

    def cstate
      env.cstate
    end

    def cstate=(val)
      env.cstate = val
    end

    def istate
      env.istate
    end

    def istate=(val)
      env.istate = val
    end
  end

  # Status predicates
  module StatusPredicates
    def success?
      status == :SUCCESS
    end

    def failure?
      status == :FAILURE
    end

    def error?
      status == :ERROR
    end
  end

  class ConnectionResponse
    prepend WithConnectionState
    include StatusPredicates
  end

  class CommandMessage
    prepend WithConnectionState
  end

  class CommandResponse
    prepend WithConnectionState
    include StatusPredicates
  end

  class DisconnectRequest
    prepend WithConnectionState
  end

  class DisconnectResponse
    include StatusPredicates
  end

  # TODO: Move sid to env in the future version of RPC proto
  unless Env.instance_methods(false).include?(:sid)
    class Env
      attr_accessor :sid
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
anycable-core-1.6.0.rc.1 lib/anycable/rpc.rb
anycable-core-1.5.2 lib/anycable/rpc.rb
anycable-core-1.5.1 lib/anycable/rpc.rb
anycable-core-1.5.0 lib/anycable/rpc.rb
anycable-core-1.4.4 lib/anycable/rpc.rb
anycable-core-1.5.0.rc.1 lib/anycable/rpc.rb
anycable-core-1.4.3 lib/anycable/rpc.rb
anycable-core-1.4.2 lib/anycable/rpc.rb
anycable-core-1.4.1 lib/anycable/rpc.rb
anycable-core-1.4.0 lib/anycable/rpc.rb
anycable-core-1.4.0.rc.3 lib/anycable/rpc.rb
anycable-core-1.4.0.rc.2 lib/anycable/rpc.rb
anycable-core-1.4.0.rc.1 lib/anycable/rpc.rb
anycable-core-1.4.0.pre.rc.1 lib/anycable/rpc.rb
anycable-core-1.3.1 lib/anycable/rpc.rb
anycable-core-1.3.0 lib/anycable/rpc.rb
anycable-core-1.2.5 lib/anycable/rpc.rb
anycable-core-1.2.4 lib/anycable/rpc.rb
anycable-core-1.2.3 lib/anycable/rpc.rb