Class: JsonFfiClient::Connection
- Inherits:
-
Object
- Object
- JsonFfiClient::Connection
- Extended by:
- FFI::Library
- Defined in:
- lib/json_ffi_client.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ Connection
constructor
A new instance of Connection.
- #run(method, path, params = {}, headers = {}) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Connection
Returns a new instance of Connection.
22 |
# File 'lib/json_ffi_client.rb', line 22 def initialize(*args); end |
Class Method Details
.configured_for(library_name, base_path) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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.}. Maybe '#{RUBY_PLATFORM}' is not supported.") end attach_function :free, "#{library_name}_free".to_sym, [Response], :void self end |
.method_missing(message, *args, &blk) ⇒ Object
46 47 48 49 |
# File 'lib/json_ffi_client.rb', line 46 def self.method_missing(, *args, &blk) attach_function , , [:string], Response send(, *args) end |
Instance Method Details
#run(method, path, params = {}, headers = {}) ⇒ Object
51 52 53 54 |
# 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 |