Class: Ruddy::Connection
- Inherits:
-
Object
- Object
- Ruddy::Connection
- Defined in:
- lib/ruddy/connection.rb
Instance Attribute Summary collapse
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #execute(command) ⇒ Object
-
#initialize(service, topic, options = {}) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(service, topic, options = {}) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 13 14 |
# File 'lib/ruddy/connection.rb', line 7 def initialize(service, topic, = {}) @service = service @topic = topic @timeout = .fetch(:timeout, 3000) start connect end |
Instance Attribute Details
#service ⇒ Object (readonly)
Returns the value of attribute service.
4 5 6 |
# File 'lib/ruddy/connection.rb', line 4 def service @service end |
#timeout ⇒ Object
Returns the value of attribute timeout.
5 6 7 |
# File 'lib/ruddy/connection.rb', line 5 def timeout @timeout end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
4 5 6 |
# File 'lib/ruddy/connection.rb', line 4 def topic @topic end |
Class Method Details
.open(*args) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruddy/connection.rb', line 38 def self.open(*args) connection = new(*args) return connection unless block_given? begin yield connection ensure connection.close end end |
Instance Method Details
#close ⇒ Object
16 17 18 19 |
# File 'lib/ruddy/connection.rb', line 16 def close @closed = true DDE.stop(instance) end |
#closed? ⇒ Boolean
21 22 23 |
# File 'lib/ruddy/connection.rb', line 21 def closed? @closed end |
#execute(command) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ruddy/connection.rb', line 25 def execute(command) raise IOError.new("closed connection") if closed? buffer = FFI::MemoryPointer.from_string(command) result = FFI::MemoryPointer.new(:uint) data = DDE.client_transaction(buffer, buffer.size, conversation, nil, 0, DDE::XTYP_EXECUTE, timeout, result) raise Error.new("command execution failed", DDE.last_error(instance)) if data.null? DDE.free_data_handle(data) return result.read_uint end |