Module: TD::Api::Dl

Extended by:
Fiddle::Importer
Defined in:
lib/tdlib/api.rb

Class Method Summary collapse

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
# File 'lib/tdlib/api.rb', line 43

def method_missing(method_name, *args)
  @mutex.synchronize do
    return if respond_to?(method_name)
    dlload(find_lib)

    extern 'void* td_json_client_create()'
    extern 'void* td_json_client_send(void*, char*)'
    extern 'char* td_json_client_receive(void*, double)'
    extern 'char* td_json_client_execute(void*, char*)'
    extern 'void td_set_log_verbosity_level(int)'
    extern 'void td_json_client_destroy(void*)'
    extern 'void td_set_log_file_path(char*)'

    undef method_missing
    public_send(method_name, *args)
  end
end

Class Method Details

.find_libObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tdlib/api.rb', line 61

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
  return `ldconfig -p | grep libtdjson`[/=> (.*?)\n/m, 1] if os == :linux && lib_path.nil?
  raise TD::MissingLibPathError unless lib_path
  File.join(lib_path, file_name)
end

.lib_extensionObject



74
75
76
77
78
79
80
81
# File 'lib/tdlib/api.rb', line 74

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
# File 'lib/tdlib/api.rb', line 43

def method_missing(method_name, *args)
  @mutex.synchronize do
    return if respond_to?(method_name)
    dlload(find_lib)

    extern 'void* td_json_client_create()'
    extern 'void* td_json_client_send(void*, char*)'
    extern 'char* td_json_client_receive(void*, double)'
    extern 'char* td_json_client_execute(void*, char*)'
    extern 'void td_set_log_verbosity_level(int)'
    extern 'void td_json_client_destroy(void*)'
    extern 'void td_set_log_file_path(char*)'

    undef method_missing
    public_send(method_name, *args)
  end
end

.osObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/tdlib/api.rb', line 83

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