Class: GObjectIntrospection::IBaseInfo
- Inherits:
-
Object
- Object
- GObjectIntrospection::IBaseInfo
- Defined in:
- lib/ffi-gobject_introspection/i_base_info.rb
Overview
Wraps GIBaseInfo struct, the base type for all info types. Decendant types will be implemented as needed.
Direct Known Subclasses
IArgInfo, ICallableInfo, IConstantInfo, IFieldInfo, IPropertyInfo, IRegisteredTypeInfo, ITypeInfo, IUnresolvedInfo, IValueInfo
Class Method Summary collapse
-
.build_array_method(method, single = nil) ⇒ Object
This is a helper method to construct a method returning an array, out of the methods returning their number and the individual elements.
-
.build_finder_method(method, counter = nil, fetcher = nil) ⇒ Object
This is a helper method to construct a method for finding an element, out of the methods returning their number and the individual elements.
- .make_finalizer(lib, ptr) ⇒ Object
- .wrap(ptr) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attribute(name) ⇒ Object
- #container ⇒ Object
- #deprecated? ⇒ Boolean
- #info_type ⇒ Object
-
#initialize(ptr, lib = Lib) ⇒ IBaseInfo
constructor
A new instance of IBaseInfo.
- #name ⇒ Object
- #namespace ⇒ Object
- #safe_namespace ⇒ Object
- #to_ptr ⇒ Object
Constructor Details
#initialize(ptr, lib = Lib) ⇒ IBaseInfo
Returns a new instance of IBaseInfo.
7 8 9 10 11 12 13 14 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 7 def initialize(ptr, lib = Lib) raise ArgumentError, 'ptr must not be null' if ptr.null? ObjectSpace.define_finalizer self, self.class.make_finalizer(lib, ptr) @gobj = ptr @lib = lib end |
Class Method Details
.build_array_method(method, single = nil) ⇒ Object
This is a helper method to construct a method returning an array, out of the methods returning their number and the individual elements.
For example, given the methods n_foos and foo(i), this method will create an additional method foos returning all foos.
Provide the second parameter if the plural is not trivially constructed by adding s to the singular.
Examples:
build_array_method :fields
build_array_mehtod :properties, :property
build_array_method :get_methods
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 39 def self.build_array_method(method, single = nil) method = method.to_s single ||= method.to_s[0..-2] count = method.sub(/^(get_)?/, '\\1n_') class_eval " def \#{method}\n (0..(\#{count} - 1)).map do |i|\n \#{single} i\n end\n end\n CODE\nend\n", __FILE__, __LINE__ + 1 |
.build_finder_method(method, counter = nil, fetcher = nil) ⇒ Object
This is a helper method to construct a method for finding an element, out of the methods returning their number and the individual elements.
For example, given the methods n_foos and foo(i), this method will create an additional method find_foo returning the foo with the matching name.
Optionally provide counter and fetcher methods if they cannot be trivially derived from the finder method.
Examples:
build_finder_method :find_field
build_finder_method :find_property, :n_properties
build_finder_method :find_method, :get_n_methods, :get_method
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 68 def self.build_finder_method(method, counter = nil, fetcher = nil) method = method.to_s single = method.sub(/^find_/, '') counter ||= "n_#{single}s" fetcher ||= single class_eval " def \#{method}(name)\n name = name.to_s\n \#{counter}.times do |i|\n it = \#{fetcher}(i)\n return it if it.name == name\n end\n nil\n end\n CODE\nend\n", __FILE__, __LINE__ + 1 |
.make_finalizer(lib, ptr) ⇒ Object
16 17 18 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 16 def self.make_finalizer(lib, ptr) proc { lib.g_base_info_unref ptr } end |
.wrap(ptr) ⇒ Object
115 116 117 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 115 def self.wrap(ptr) new ptr unless ptr.null? end |
Instance Method Details
#==(other) ⇒ Object
119 120 121 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 119 def ==(other) other.is_a?(IBaseInfo) && Lib.g_base_info_equal(@gobj, other) end |
#attribute(name) ⇒ Object
111 112 113 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 111 def attribute(name) Lib.g_base_info_get_attribute @gobj, name end |
#container ⇒ Object
101 102 103 104 105 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 101 def container ptr = Lib.g_base_info_get_container @gobj Lib.g_base_info_ref ptr IRepository.wrap_ibaseinfo_pointer ptr end |
#deprecated? ⇒ Boolean
107 108 109 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 107 def deprecated? Lib.g_base_info_is_deprecated @gobj end |
#info_type ⇒ Object
89 90 91 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 89 def info_type Lib.g_base_info_get_type @gobj end |
#name ⇒ Object
85 86 87 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 85 def name Lib.g_base_info_get_name @gobj end |
#namespace ⇒ Object
93 94 95 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 93 def namespace Lib.g_base_info_get_namespace @gobj end |
#safe_namespace ⇒ Object
97 98 99 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 97 def safe_namespace namespace.gsub(/^./, &:upcase) end |
#to_ptr ⇒ Object
20 21 22 |
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 20 def to_ptr @gobj end |