Class: Weskit::MP::Connection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/weskit/mp/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker, options = {}) ⇒ Connection

Returns a new instance of Connection.



26
27
28
29
30
31
# File 'lib/weskit/mp/connection.rb', line 26

def initialize worker, options = {}
  @options = defaults.merge options

  @adapter = Adapter.new self, @options[:debug]
  @worker  = worker
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



10
11
12
# File 'lib/weskit/mp/connection.rb', line 10

def adapter
  @adapter
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/weskit/mp/connection.rb', line 10

def options
  @options
end

#socketObject (readonly)

Returns the value of attribute socket.



10
11
12
# File 'lib/weskit/mp/connection.rb', line 10

def socket
  @socket
end

Instance Method Details

#closeObject



13
14
15
# File 'lib/weskit/mp/connection.rb', line 13

def close
  @socket.close
end

#defaultsObject



17
18
19
20
21
22
23
24
# File 'lib/weskit/mp/connection.rb', line 17

def defaults
  {
    :debug   => false,
    :host    => 'server.wesnoth.org',
    :port    => 15000,
    :version => '1.10.0'
  }
end

#openObject



33
34
35
36
37
38
39
40
41
# File 'lib/weskit/mp/connection.rb', line 33

def open
  @socket = socket_for destination_socket
  @worker.
  
  if block_given?
    result = yield
    close ; result
  end
end