Module: TD::Api::Dl
- Extended by:
- FFI::Library
- Defined in:
- lib/tdlib/api.rb
Class Method Summary collapse
- .find_lib ⇒ Object
- .lib_extension ⇒ Object
- .method_missing(method_name, *args) ⇒ Object
- .os ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object (private)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tdlib/api.rb', line 43 def method_missing(method_name, *args) @mutex.synchronize do return public_send(method_name, *args) if respond_to?(method_name) find_lib attach_function :td_json_client_create, [], :pointer attach_function :td_json_client_receive, [:pointer, :double], :string, blocking: true attach_function :td_json_client_send, [:pointer, :string], :pointer, blocking: true attach_function :td_json_client_execute, [:pointer, :string], :string, blocking: true attach_function :td_json_client_destroy, [:pointer], :void attach_function :td_set_log_file_path, [:string], :int attach_function :td_set_log_max_file_size, [:long_long], :void attach_function :td_set_log_verbosity_level, [:int], :void undef method_missing public_send(method_name, *args) end end |
Class Method Details
.find_lib ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tdlib/api.rb', line 63 def find_lib file_name = "libtdjson.#{lib_extension}" lib_path = if TD.config.lib_path TD.config.lib_path elsif defined?(Rails) && File.exist?(Rails.root.join('vendor', file_name)) Rails.root.join('vendor') end full_path = File.join(lib_path.to_s, file_name) ffi_lib full_path full_path rescue LoadError ffi_lib 'tdjson' ffi_libraries.first.name end |
.lib_extension ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/tdlib/api.rb', line 79 def lib_extension case os when :windows then 'dll' when :macos then 'dylib' when :linux then 'so' else raise "#{os} OS is not supported" end end |
.method_missing(method_name, *args) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tdlib/api.rb', line 43 def method_missing(method_name, *args) @mutex.synchronize do return public_send(method_name, *args) if respond_to?(method_name) find_lib attach_function :td_json_client_create, [], :pointer attach_function :td_json_client_receive, [:pointer, :double], :string, blocking: true attach_function :td_json_client_send, [:pointer, :string], :pointer, blocking: true attach_function :td_json_client_execute, [:pointer, :string], :string, blocking: true attach_function :td_json_client_destroy, [:pointer], :void attach_function :td_set_log_file_path, [:string], :int attach_function :td_set_log_max_file_size, [:long_long], :void attach_function :td_set_log_verbosity_level, [:int], :void undef method_missing public_send(method_name, *args) end end |
.os ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/tdlib/api.rb', line 88 def os host_os = RbConfig::CONFIG['host_os'] case host_os when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ :windows when /darwin|mac os/ :macos when /linux/ :linux when /solaris|bsd/ :unix else raise "Unknown os: #{host_os.inspect}" end end |