Class: RubyMVC::Toolkit::Widget
- Inherits:
-
AbstractWidget
- Object
- AbstractWidget
- RubyMVC::Toolkit::Widget
- 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.
Class Attribute Summary collapse
-
.peer_class ⇒ Object
Returns the value of attribute peer_class.
Instance Attribute Summary collapse
-
#peer ⇒ Object
readonly
Returns the value of attribute peer.
Class Method Summary collapse
-
.api_methods(*args) ⇒ Object
(also: api_method)
This method is used to manage the API methods available to the toolkit widgets.
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ Widget
constructor
A new instance of Widget.
-
#method_missing(method, *args, &block) ⇒ Object
This method will forward only those registered API methods to the peer class.
Methods included from SignalHandler::ClassMethods
#signal, #signals, #valid_signal!, #valid_signal?
Methods included from SignalHandler
#signal_connect, #signal_disconnect, #signal_emit
Constructor Details
#initialize(*args, &block) ⇒ Widget
Returns a new instance of Widget.
68 69 70 71 72 73 74 75 |
# File 'lib/ruby_mvc/toolkit/widget.rb', line 68 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…
85 86 87 88 89 90 91 |
# File 'lib/ruby_mvc/toolkit/widget.rb', line 85 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_class ⇒ Object
Returns the value of attribute peer_class.
45 46 47 |
# File 'lib/ruby_mvc/toolkit/widget.rb', line 45 def peer_class @peer_class end |
Instance Attribute Details
#peer ⇒ Object (readonly)
Returns the value of attribute peer.
65 66 67 |
# File 'lib/ruby_mvc/toolkit/widget.rb', line 65 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.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ruby_mvc/toolkit/widget.rb', line 52 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 |