Sha256: 0869f6c989f1ea4703deb818499b4e9c916af3ddcfa2e342c15b9afb308d1abe

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

class ProxyReceiver : BasicObject {
  """
  A ProxyReceiver is an object which proxies all message sends to it to 2 other objects.
  It will send each message first to its @proxy instance variable and then to the @obj instance variable.
  """

  def initialize: @proxy for: @obj {
    """
    @proxy Proxy receiver for @obj.
    @obj Original receiver object.

    Initializes a new ProxyReceiver with @proxy for @obj.
    """

    self
  }

  def unknown_message: msg with_params: params {
    """
    @msg Incoming message name.
    @params Paremeters of incoming message send.

    Forwards all incoming messages to @self to @@proxy and then @@obj.
    """

    @proxy receive_message: msg with_params: params
    @obj receive_message: msg with_params: params
  }
}

Proxy = ProxyReceiver

class RespondsToProxy : BasicObject {
  """
  A RespondsToProxy is a Proxy that forwards any message sent to it to it's @target instance variable
  only if it responds to that message. Any messages that @target doesn't respond to simply won't be sent
  and @nil will be returned.
  """

  def initialize: @target {
    """
    @target Target receiver object.

    Initializes a new RespondsToProxy for @target.
    """

    self
  }

  def unknown_message: msg with_params: params {
    """
    @msg Incoming message name.
    @params Paremeters of incoming message send.

    Forwards all incoming message to @self to @@target
    only if @@target responds to them.
    """

    if: (@target responds_to?: msg) then: {
      @target receive_message: msg with_params: params
    }
  }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fancy-0.6.0 lib/proxy.fy
fancy-0.5.0 lib/proxy.fy
fancy-0.4.0 lib/proxy.fy