Class: Pod4::Connection
- Inherits:
-
Object
- Object
- Pod4::Connection
- Defined in:
- lib/pod4/connection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data_layer_options ⇒ Object
Returns the value of attribute data_layer_options.
-
#interface_class ⇒ Object
readonly
Returns the value of attribute interface_class.
Instance Method Summary collapse
-
#client(interface) ⇒ Object
When an interface wants a connection, it calls connection.client.
-
#close(interface) ⇒ Object
Close the connection.
-
#initialize(args) ⇒ Connection
constructor
Intitialise a Connection.
Constructor Details
#initialize(args) ⇒ Connection
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)`
18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |
Instance Attribute Details
#data_layer_options ⇒ Object
Returns the value of attribute data_layer_options.
10 11 12 |
# File 'lib/pod4/connection.rb', line 10 def @data_layer_options end |
#interface_class ⇒ Object (readonly)
Returns the value of attribute interface_class.
9 10 11 |
# File 'lib/pod4/connection.rb', line 9 def interface_class @interface_class end |
Instance Method Details
#client(interface) ⇒ Object
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`.
38 39 40 41 42 |
# 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) ⇒ Object
Close the connection.
In the case of a single connection, this is probably not going to get used much. But.
48 49 50 51 52 53 |
# File 'lib/pod4/connection.rb', line 48 def close(interface) fail_bad_interfaces(interface) interface.close_connection @client = nil return self end |