Class: GObjectIntrospection::IBaseInfo

Inherits:
Object
  • Object
show all
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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, lib = Lib) ⇒ IBaseInfo

Returns a new instance of IBaseInfo.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 5

def initialize ptr, lib=Lib
  raise ArgumentError, "ptr must not be null" if ptr.null?

  unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
    ObjectSpace.define_finalizer self, self.class.make_finalizer(lib, ptr)
  end

  @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 args.

Provide the second parameter if the plural is not trivially constructed by adding s to the singular.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 32

def self.build_array_method method, single = nil
  method = method.to_s
  single ||= method[0..-2]
  count = method.sub(/^(get_)?/, "\\1n_")
  self.class_eval <<-CODE
    def #{method}
      (0..(#{count} - 1)).map do |i|
        #{single} i
      end
    end
  CODE
end

.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



70
71
72
73
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 70

def self.wrap ptr
  return nil if ptr.null?
  return new ptr
end

Instance Method Details

#==(other) ⇒ Object



75
76
77
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 75

def == other
  Lib.g_base_info_equal @gobj, other.to_ptr
end

#containerObject



61
62
63
64
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 61

def container
  ptr = Lib.g_base_info_get_container @gobj
  IRepository.wrap_ibaseinfo_pointer ptr
end

#deprecated?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 66

def deprecated?
  Lib.g_base_info_is_deprecated @gobj
end

#info_typeObject



49
50
51
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 49

def info_type
  Lib.g_base_info_get_type @gobj
end

#nameObject



45
46
47
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 45

def name
  Lib.g_base_info_get_name @gobj
end

#namespaceObject



53
54
55
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 53

def namespace
  Lib.g_base_info_get_namespace @gobj
end

#safe_namespaceObject



57
58
59
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 57

def safe_namespace
  namespace.gsub(/^(.)/) { $1.upcase }
end

#to_ptrObject



20
21
22
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 20

def to_ptr
  @gobj
end