Module: Quickbooks::Adaptability
- Included in:
- Quickbooks
- Defined in:
- lib/quickbooks/adaptability.rb
Class Method Summary collapse
Instance Method Summary collapse
- #connected? ⇒ Boolean
-
#connection ⇒ Object
Returns the current Connection.
-
#connection=(conn) ⇒ Object
Sets the current Connection.
-
#establish_connection(*args) ⇒ Object
Establishes a connection to the Quickbooks API.
- #use_adapter(adapter, *args) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
23 24 25 |
# File 'lib/quickbooks/adaptability.rb', line 23 def self.extended(base) base.send(:class_variable_set, :@@connection_adapter, nil) end |
Instance Method Details
#connected? ⇒ Boolean
63 64 65 |
# File 'lib/quickbooks/adaptability.rb', line 63 def connected? @connection.nil? ? false : @connection.connected? end |
#connection ⇒ Object
Returns the current Connection
48 49 50 51 |
# File 'lib/quickbooks/adaptability.rb', line 48 def connection @@connection_args ||= [] (@connection ||= nil) || (@@connection ||= self.establish_connection(*(@@connection_args))) end |
#connection=(conn) ⇒ Object
Sets the current Connection.
This is normally not needed, but in the case that you may want to connect a separate connection to Quickbooks, you can use this method to explicitly set the connection in a class that inherits from Quickbooks::Base.
Quickbooks::Base.connection = Quickbooks::Connection.new('My Test App', 'C:\\Some File.QBW', 'user', 'pass')
58 59 60 61 |
# File 'lib/quickbooks/adaptability.rb', line 58 def connection=(conn) raise ArgumentError, "Cannot set connection to anything but a (*)Adapter::Connection object" unless conn.class.name =~ /Adapter::Connection$/ @connection = conn end |
#establish_connection(*args) ⇒ Object
Establishes a connection to the Quickbooks API
42 43 44 45 |
# File 'lib/quickbooks/adaptability.rb', line 42 def establish_connection(*args) @@connection_adapter ||= use_adapter(:spew) @@connection = @@connection_adapter.new(*args) end |
#use_adapter(adapter, *args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/quickbooks/adaptability.rb', line 27 def use_adapter(adapter, *args) # Should complain if the adapter doesn't exist. @@connection_adapter = try_retry(1, NameError, :before_retry => lambda {require "quickbooks/adapters/#{adapter.to_s}_adapter"}) { Object.module_eval("::Quickbooks::Adapters::#{adapter.to_s.camel_case}Adapter::Connection", __FILE__, __LINE__) } @@connection ||= nil @connection ||= nil @@connection.close if @@connection @connection.close if @connection @@connection = @connection = nil @@connection_args = args return @@connection_adapter end |