Class: Grocer::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/grocer/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.



8
9
10
11
12
13
14
# File 'lib/grocer/connection.rb', line 8

def initialize(options = {})
  @certificate = options.fetch(:certificate) { nil }
  @passphrase = options.fetch(:passphrase) { nil }
  @gateway = options.fetch(:gateway) { fail NoGatewayError }
  @port = options.fetch(:port) { fail NoPortError }
  @retries = options.fetch(:retries) { 3 }
end

Instance Attribute Details

#certificateObject (readonly)

Returns the value of attribute certificate.



6
7
8
# File 'lib/grocer/connection.rb', line 6

def certificate
  @certificate
end

#gatewayObject (readonly)

Returns the value of attribute gateway.



6
7
8
# File 'lib/grocer/connection.rb', line 6

def gateway
  @gateway
end

#passphraseObject (readonly)

Returns the value of attribute passphrase.



6
7
8
# File 'lib/grocer/connection.rb', line 6

def passphrase
  @passphrase
end

#portObject (readonly)

Returns the value of attribute port.



6
7
8
# File 'lib/grocer/connection.rb', line 6

def port
  @port
end

#retriesObject (readonly)

Returns the value of attribute retries.



6
7
8
# File 'lib/grocer/connection.rb', line 6

def retries
  @retries
end

Instance Method Details

#connectObject



28
29
30
# File 'lib/grocer/connection.rb', line 28

def connect
  ssl.connect unless ssl.connected?
end

#read(size = nil, buf = nil) ⇒ Object



16
17
18
19
20
# File 'lib/grocer/connection.rb', line 16

def read(size = nil, buf = nil)
  with_connection do
    ssl.read(size, buf)
  end
end

#write(content) ⇒ Object



22
23
24
25
26
# File 'lib/grocer/connection.rb', line 22

def write(content)
  with_connection do
    ssl.write(content)
  end
end