Class: Ruber::KTextEditorWrapper::InterfaceProxy
- Inherits:
-
Object
- Object
- Ruber::KTextEditorWrapper::InterfaceProxy
- Defined in:
- lib/ruber/editor/ktexteditor_wrapper.rb
Overview
Helper class which, given a Qt::Object implementing different interfaces, allows to access method provided by one interface without exposing the object itself.
Instance Method Summary (collapse)
-
- (InterfaceProxy) initialize(obj)
constructor
Creates a new InterfaceProxy.
-
- (Object) interface(iface)
Sets the interface to which the object is going to be cast.
-
- (Object) method_missing(name, *args, &blk)
Passes the method call to the object cast to the current interface.
Constructor Details
- (InterfaceProxy) initialize(obj)
Creates a new InterfaceProxy. obj is the Qt::Object to cast to the appropriate interface
53 54 55 56 |
# File 'lib/ruber/editor/ktexteditor_wrapper.rb', line 53 def initialize obj @obj = obj @interface = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(name, *args, &blk)
Passes the method call to the object cast to the current interface. If the argument list contains instances of classes which mix-in KTextEditorWrapper, they’re replaced with the object they wrap before being passed to the interface.
79 80 81 82 |
# File 'lib/ruber/editor/ktexteditor_wrapper.rb', line 79 def method_missing name, *args, &blk args.map!{|a| a.is_a?(KTextEditorWrapper) ? a.send(:internal) : a} @interface.send name, *args, &blk end |
Instance Method Details
- (Object) interface=(iface)
Sets the interface to which the object is going to be cast. iface can be either the name of an interface, as symbol or string, both in camelcase or snakecase (withouth the KTextEditor namespace) or the class itself. After a call to this method (and until the next one) method_missing will redirect all unknown method calls to this interface.
65 66 67 68 69 70 71 72 |
# File 'lib/ruber/editor/ktexteditor_wrapper.rb', line 65 def interface= iface cls = if iface.is_a? Class then iface else name = iface.to_s.split('_').map(&:capitalize).join '' KTextEditor.const_get(name) end @interface = @obj.qobject_cast cls end |