Class: Quickbooks::Adapters::OleAdapter::Ole

Inherits:
Object
  • Object
show all
Defined in:
lib/quickbooks/adapters/ole_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ole_app, type_library = nil) ⇒ Ole

Pass in the OLE name of the application you want connected to, and the name of a type library, if you need one.



25
26
27
28
29
30
# File 'lib/quickbooks/adapters/ole_adapter.rb', line 25

def initialize(ole_app, type_library=nil)
  @ole_app = ole_app
  @type_library = type_library
  @ole = WIN32OLE.new(ole_app)
  self.classes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

method_missing sends all other methods to the OLE object, so you can treat this object as your OLE object.



59
60
61
# File 'lib/quickbooks/adapters/ole_adapter.rb', line 59

def method_missing(method_name, *args)
  @ole.send(method_name, *args)
end

Instance Attribute Details

#oleObject (readonly)

Simply holds the actual OLE object.



22
23
24
# File 'lib/quickbooks/adapters/ole_adapter.rb', line 22

def ole
  @ole
end

Instance Method Details

#classesObject

:nodoc:



47
48
49
50
# File 'lib/quickbooks/adapters/ole_adapter.rb', line 47

def classes #:nodoc:
  return nil unless @type_library
  @classes ||= WIN32OLE_TYPE.ole_classes(@type_library)
end

#constant_for(class_name) ⇒ Object

:nodoc:



52
53
54
55
56
# File 'lib/quickbooks/adapters/ole_adapter.rb', line 52

def constant_for(class_name) #:nodoc:
  return nil unless @type_library
  @constant_for ||= {}
  @constant_for[class_name] ||= WIN32OLE_TYPE.new(@type_library, class_name)
end

#get_variable(var_name) ⇒ Object

Finds an OLE variable in the OLE type library, if you specified one in new(). This navigates the OLE classes and constants for you and returns the variable that matches the var_name you specify. This is used with Quickbooks to get the qbFileOpenDoNotCare parameter to pass to the OpenConnection2 method:

@quickbooks = Ole.new('QBXMLRP2.RequestProcessor', 'QBXMLRP2 1.0 Type Library')
@quickbooks.OpenConnection2('','Sample Application',@quickbooks.get_variable('localQBD'))
@session = @quickbooks.BeginSession('',@quickbooks.get_variable('qbFileOpenDoNotCare'))
...


39
40
41
42
43
44
45
# File 'lib/quickbooks/adapters/ole_adapter.rb', line 39

def get_variable(var_name)
  return nil unless @type_library
  self.classes.each do |class_name|
    found = self.constant_for(class_name.name).variables.find {|var| var.name == var_name}
    return found if found
  end
end