class Pod4::Connection
Attributes
data_layer_options[RW]
interface_class[R]
Public Class Methods
new(args)
click to toggle source
Intitialise a Connection
. You must pass a Pod4::Interface
class. The connection object will only accept calls from instances of this class.
`conn = Pod4::Connection.new
(interface: MyInterface)`
# File lib/pod4/connection.rb, line 18 def initialize(args) raise ArgumentError, "Connection#new needs a Hash" unless args.is_a? Hash raise ArgumentError, "You must pass a Pod4::Interface" \ unless args[:interface] \ && args[:interface].is_a?(Class) \ && args[:interface].ancestors.include?(Interface) @interface_class = args[:interface] @data_layer_options = nil @client = nil @options = nil end
Public Instance Methods
client(interface)
click to toggle source
When an interface wants a connection, it calls connection.client. If the connection does not have one, it asks the interface for one.…
Interface
is an instance of whatever class you passed to Connection
when you initialised it. That is: when an interface wants a connection, it passes `self`.
# File lib/pod4/connection.rb, line 38 def client(interface) fail_bad_interfaces(interface) @client ||= interface.new_connection(@data_layer_options) @client end
close(interface)
click to toggle source
Close the connection.
In the case of a single connection, this is probably not going to get used much. But.
# File lib/pod4/connection.rb, line 48 def close(interface) fail_bad_interfaces(interface) interface.close_connection @client = nil return self end
Private Instance Methods
fail_bad_interfaces(f)
click to toggle source
# File lib/pod4/connection.rb, line 57 def fail_bad_interfaces(f) raise ArgumentError, "That's not a #@interface_class", caller \ unless f.kind_of?(@interface_class) end