class JsonFfiClient::Connection

Public Class Methods

configured_for(library_name, base_path) click to toggle source
# File lib/json_ffi_client.rb, line 24
def self.configured_for(library_name, base_path)
  @@library_name = library_name

  lib_ext = if(FFI::Platform.mac?)
    "dylib"
  elsif(FFI::Platform.windows?)
    "dll"
  else
    "so"
  end

  begin 
    ffi_lib File.join(base_path, "lib#{library_name}.#{lib_ext}")
  rescue LoadError => e
    raise Error
      .new("#{e.message}. Maybe '#{RUBY_PLATFORM}' is not supported.")
  end

  attach_function :free, "#{library_name}_free".to_sym, [Response], :void
  self
end
method_missing(message, *args, &blk) click to toggle source
# File lib/json_ffi_client.rb, line 46
def self.method_missing(message, *args, &blk)
  attach_function message, message, [:string], Response
  send(message, *args)
end
new(*args) click to toggle source
# File lib/json_ffi_client.rb, line 22
def initialize(*args); end

Public Instance Methods

run(method, path, params = {}, headers = {}) click to toggle source
# File lib/json_ffi_client.rb, line 51
def run(method, path, params = {}, headers = {})
  raise JsonFfiError.new("Connection not configured") unless @@library_name
  self.class.send([@@library_name, method, path].join("_"), params.to_json)
end