Class: PureMVC::Proxy

Inherits:
Notifier show all
Defined in:
src/patterns/proxy/proxy.rb

Overview

A base IProxy implementation.

In PureMVC, Proxy classes are used to manage parts of the application’s data model.

A Proxy might simply manage a reference to a local data object, in which case interacting with it might involve setting and getting of its data in a synchronous fashion.

Proxy classes are also used to encapsulate the application’s interaction with remote services to save or retrieve data. In this case, we adopt an asynchronous idiom: setting data (or calling a method) on the Proxy and listening for a Notification to be sent when the Proxy has retrieved the data from the service.

See Also:

Constant Summary collapse

NAME =

The name of the Proxy.

'Proxy'

Constants inherited from Notifier

Notifier::MULTITON_MSG

Instance Attribute Summary collapse

Attributes inherited from Notifier

#multiton_key

Instance Method Summary collapse

Methods inherited from Notifier

#facade, #initialize_notifier, #send_notification

Constructor Details

#initialize(name = nil, data = nil) ⇒ Proxy

Initializes a new Proxy instance.

Parameters:

  • name (String, nil) (defaults to: nil)

    the name of the proxy

  • data (Object, nil) (defaults to: nil)

    optional data to be managed by the proxy



38
39
40
41
42
# File 'src/patterns/proxy/proxy.rb', line 38

def initialize(name = nil, data = nil)
  super()
  @name = name || NAME
  @data = data
end

Instance Attribute Details

#dataObject?

Returns The data managed by the proxy.

Returns:

  • (Object, nil)

    The data managed by the proxy



32
33
34
# File 'src/patterns/proxy/proxy.rb', line 32

def data
  @data
end

#nameString (readonly)

Returns The proxy name.

Returns:

  • (String)

    The proxy name



29
30
31
# File 'src/patterns/proxy/proxy.rb', line 29

def name
  @name
end

Instance Method Details

#on_registerObject

Called by the Model when the Proxy is registered



45
# File 'src/patterns/proxy/proxy.rb', line 45

def on_register; end

#on_removeObject

Called by the Model when the Proxy is removed



48
# File 'src/patterns/proxy/proxy.rb', line 48

def on_remove; end