Class: GirFFI::ClassBase
- Inherits:
-
Object
- Object
- GirFFI::ClassBase
- Extended by:
- Forwardable
- Defined in:
- lib/gir_ffi/class_base.rb
Overview
Base class for all generated classes. Contains code for dealing with the generated Struct classes.
Direct Known Subclasses
Class Method Summary collapse
- ._allocate ⇒ Object
-
.direct_wrap(ptr) ⇒ Object
Wrap the passed pointer in an instance of the current class.
-
.from(val) ⇒ Object
Pass-through casting method.
- .gir_ffi_builder ⇒ Object
- .gir_info ⇒ Object
- .setup_and_call(method, *arguments, &block) ⇒ Object
- .setup_instance_method(name) ⇒ Object
- .setup_method(name) ⇒ Object
-
.wrap(ptr) ⇒ Object
Wrap the passed pointer in an instance of the current class, or a descendant type if applicable.
Instance Method Summary collapse
Class Method Details
._allocate ⇒ Object
72 73 74 75 76 |
# File 'lib/gir_ffi/class_base.rb', line 72 def _allocate obj = _real_new obj.instance_variable_set :@struct, self::Struct.new obj end |
.direct_wrap(ptr) ⇒ Object
Wrap the passed pointer in an instance of the current class. Will not do any casting to subtypes.
65 66 67 68 69 70 |
# File 'lib/gir_ffi/class_base.rb', line 65 def direct_wrap ptr return nil if !ptr or ptr.null? obj = _real_new obj.instance_variable_set :@struct, self::Struct.new(ptr.to_ptr) obj end |
.from(val) ⇒ Object
Pass-through casting method. This may become a type checking method. It is overridden by GValue to implement wrapping of plain Ruby objects.
81 82 83 |
# File 'lib/gir_ffi/class_base.rb', line 81 def from val val end |
.gir_ffi_builder ⇒ Object
42 43 44 |
# File 'lib/gir_ffi/class_base.rb', line 42 def gir_ffi_builder self.const_get :GIR_FFI_BUILDER end |
.gir_info ⇒ Object
38 39 40 |
# File 'lib/gir_ffi/class_base.rb', line 38 def gir_info self.const_get :GIR_INFO end |
.setup_and_call(method, *arguments, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gir_ffi/class_base.rb', line 24 def self.setup_and_call method, *arguments, &block result = self.ancestors.any? do |klass| klass.respond_to?(:setup_method) && klass.setup_method(method.to_s) end unless result raise RuntimeError, "Unable to set up method #{method} in #{self}" end self.send method, *arguments, &block end |
.setup_instance_method(name) ⇒ Object
50 51 52 |
# File 'lib/gir_ffi/class_base.rb', line 50 def setup_instance_method name gir_ffi_builder.setup_instance_method name end |
.setup_method(name) ⇒ Object
46 47 48 |
# File 'lib/gir_ffi/class_base.rb', line 46 def setup_method name gir_ffi_builder.setup_method name end |
.wrap(ptr) ⇒ Object
Wrap the passed pointer in an instance of the current class, or a descendant type if applicable.
59 60 61 |
# File 'lib/gir_ffi/class_base.rb', line 59 def wrap ptr direct_wrap ptr end |
Instance Method Details
#setup_and_call(method, *arguments, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gir_ffi/class_base.rb', line 11 def setup_and_call method, *arguments, &block result = self.class.ancestors.any? do |klass| klass.respond_to?(:setup_instance_method) && klass.setup_instance_method(method.to_s) end unless result raise RuntimeError, "Unable to set up instance method #{method} in #{self}" end self.send method, *arguments, &block end |