Module: GPGME::Meta
- Defined in:
- lib/gpgme/ffi/meta.rb
Class Method Summary collapse
- .common_gpgme_edit(context, key, ruby_callback, ruby_handle, data, receiver) ⇒ Object
- .define_ffi_forwarder(*functions) ⇒ Object
- .define_op_edit(*functions) ⇒ Object
- .ffize_value(arg) ⇒ Object
Class Method Details
.common_gpgme_edit(context, key, ruby_callback, ruby_handle, data, receiver) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gpgme/ffi/meta.rb', line 36 def self.common_gpgme_edit(context, key, ruby_callback, ruby_handle, data, receiver) callback = FFI::Function.new(:uint, [ :pointer, :uint, :string, :int ]) do |handle, status, args, fd| ruby_callback.call ruby_handle, status, args, fd GPGME.gpgme_err_make GPGME::GPG_ERR_SOURCE_USER_1, GPGME::GPG_ERR_NO_ERROR end context.edit_callback = callback receiver.call context.context_pointer, key.context_pointer, callback, FFI::Pointer::NULL, data.context_pointer end |
.define_ffi_forwarder(*functions) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/gpgme/ffi/meta.rb', line 26 def self.define_ffi_forwarder(*functions) functions.each do |id| GPGME.define_singleton_method(id) do |*args| args = args.map! { |arg| Meta.ffize_value arg } GPGME::Library.send id, *args end end end |
.define_op_edit(*functions) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/gpgme/ffi/meta.rb', line 49 def self.define_op_edit(*functions) functions.each do |function| GPGME.define_singleton_method(function) do |*args| common_gpgme_edit *args, GPGME::Library.method(function) end end end |
.ffize_value(arg) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gpgme/ffi/meta.rb', line 3 def self.ffize_value(arg) if arg.respond_to?(:context_pointer) arg.context_pointer elsif arg.kind_of?(String) FFI::MemoryPointer.from_string arg elsif arg.kind_of?(Array) buf = FFI::Buffer.new :pointer, arg.length + 1 pointers = arg.map { |item| ffize_value item } pointers << FFI::Pointer::NULL buf.put_array_of_pointer 0, pointers buf elsif arg.nil? FFI::Pointer::NULL else arg end end |