Class QBFC::OLEWrapper
In: lib/qbfc/ole_wrapper.rb
Parent: Object

OLEWrapper is more or less the centerpiece of RubyQBFC. (Nearly) every WIN32OLE object accessed within the library is wrapped in this class, which is responsible for allowing Ruby-esque methods in place of the OLE methods.

  customer.full_name # => Customer.FullName.GetValue
  customer.full_name=(val) # => Customer.FullName.SetValue(val)

It also creates referenced objects when accessed.

  check.payee # => Entity.find_by_list_id(check.PayeeEntityRef.ListID.GetValue)
  check.account # => Account.find_by_list_id(check.AccountRef.ListID.GetValue)

When an OLE method called via OLEWrapper returns a WIN32OLE object, a new OLEWrapper object is created with the WIN32OLE object and returned.

Now, the fun (and really hackish) part. In many cases within the QBFC library, the wrapper is actually wrapping two WIN32OLE objects, the additional being a ‘setter’ object. This object is used when creating a ModRequest. In such cases, a method ending in ’=’ is always sent to both the primary and the setter objects. To facilitate this, traversing child ole_objects also traverses the child setter objects.



ole_object  [R] 
setter  [RW] 

Public Class methods

Set up wrapped object, by passing a WIN32OLE object (or a String with the name of a WIN32OLE server) Optionally, pass a setter WIN32OLE object.


    # File lib/qbfc/ole_wrapper.rb, line 31
31:     def initialize(ole_object, setter = nil)
32:       ole_object = if ole_object.kind_of?(String)
33:       @ole_object = ole_object
34:       @setter = setter
35:     end

Public Instance methods

Use [idx] syntax for objects that respond to GetAt(idx)


    # File lib/qbfc/ole_wrapper.rb, line 48
48:     def [](idx)
49:       if idx.kind_of? Integer
51:       else
52:         @ole_object[idx]
53:       end
54:     end

Return Array of ole_methods for request WIN32OLE object.


    # File lib/qbfc/ole_wrapper.rb, line 38
38:     def ole_methods
39:       @ole_object.ole_methods
40:     end

Called by method_missing of other classes. Initiates the OLEWrapper#method_missing method which is responsible for the various method conversions. sess argument is a QBFC::Session.


    # File lib/qbfc/ole_wrapper.rb, line 59
59:     def qbfc_method_missing(sess, symbol, *params)
60:       @sess = sess
61:       method_missing(symbol, *params)
62:     end

Does this OLE object respond to the given ole method?


    # File lib/qbfc/ole_wrapper.rb, line 43
43:     def respond_to_ole?(symbol)
44:       detect_ole_method?(@ole_object, symbol)
45:     end