Class: RubyMVC::Toolkit::Widget

Inherits:
Object
  • Object
show all
Extended by:
SignalHandler::ClassMethods
Includes:
SignalHandler
Defined in:
lib/ruby_mvc/toolkit/widget.rb

Overview

This class defines the base toolkit widget class. Each widget has one - and only one - UI peer that is registered automatically when the UI peer is loaded.

Direct Known Subclasses

App, Dialog, Frame, WebView

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SignalHandler::ClassMethods

signal, signals, valid_signal?

Methods included from SignalHandler

#signal_connect, #signal_disconnect, #signal_emit

Constructor Details

#initialize(*args, &block) ⇒ Widget

Returns a new instance of Widget.



61
62
63
64
65
66
67
68
# File 'lib/ruby_mvc/toolkit/widget.rb', line 61

def initialize(*args, &block)
  if pc = self.class.peer_class
    @peer = pc.new(*args, &block)
    connect_peer_signals
  else
    raise RuntimeError, "no peer class registered for #{self.class}"
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

This method will forward only those registered API methods to the peer class. Doing it this way ensures that we don’t leak APIs from the peers into applications, but that we can still be efficient in how we manage the implementations.

FIXME: there may be performance implications…



78
79
80
81
82
83
84
# File 'lib/ruby_mvc/toolkit/widget.rb', line 78

def method_missing(method, *args, &block)
  if (self.class.api_methods || []).include? method
    @peer.send(method, *args, &block)
  else
    super
  end
end

Class Attribute Details

.peer_classObject

Returns the value of attribute peer_class.



38
39
40
# File 'lib/ruby_mvc/toolkit/widget.rb', line 38

def peer_class
  @peer_class
end

Instance Attribute Details

#peerObject (readonly)

Returns the value of attribute peer.



58
59
60
# File 'lib/ruby_mvc/toolkit/widget.rb', line 58

def peer
  @peer
end

Class Method Details

.api_methods(*args) ⇒ Object Also known as: api_method

This method is used to manage the API methods available to the toolkit widgets. Methods listed here will be forwarded to the peer class if they aren’t defined by the toolkit widget subclass.



45
46
47
48
49
50
51
52
53
54
# File 'lib/ruby_mvc/toolkit/widget.rb', line 45

def api_methods(*args)
  if !@api
    @api = []
    if self.superclass.respond_to? :api_methods
      @api.concat(self.superclass.api_methods)
    end
  end
  @api.concat(args) if args.size > 0
  @api
end