Class: Caper::ErrorBuffer

Inherits:
FFI::MemoryPointer
  • Object
show all
Defined in:
lib/caper/error_buffer.rb

Constant Summary collapse

SIZE =

Size of the error buffers

256

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil) ⇒ ErrorBuffer

Creates a new ErrorBuffer object. The argument is nil and is only present for compatability with JRuby.

See github.com/ffi/ffi/issues#issue/27



21
22
23
# File 'lib/caper/error_buffer.rb', line 21

def initialize(arg=nil)
  super(SIZE)
end

Class Method Details

.createObject

Creates a new ErrorBuffer object. Because of wierdness in JRuby

when trying to subclass FFI::Buffer, always use this instead of 
'new()'

See http://github.com/ffi/ffi/issues#issue/27


12
13
14
# File 'lib/caper/error_buffer.rb', line 12

def self.create()
  new(SIZE)
end

Instance Method Details

#sizeObject

Older JRuby/ffi versions of MemoryPointer and Buffer don’t have a size method. We override it here to ensure we can use it.



34
35
36
37
38
39
40
# File 'lib/caper/error_buffer.rb', line 34

def size
  begin
    super()
  rescue NoMethodError
    SIZE
  end
end

#to_sObject

Returns the error message within the error buffer.



28
29
30
# File 'lib/caper/error_buffer.rb', line 28

def to_s
  get_string(0)
end