Class: GirFFI::Builders::ModuleBuilder

Inherits:
Object
  • Object
show all
Includes:
GirFFI::BuilderHelper
Defined in:
lib/gir_ffi/builders/module_builder.rb

Overview

Builds a module based on information found in the introspection repository.

Instance Method Summary collapse

Methods included from GirFFI::BuilderHelper

#get_or_define_class, #get_or_define_module, #optionally_define_constant

Constructor Details

#initialize(module_name, namespace: module_name, version: nil) ⇒ ModuleBuilder

Returns a new instance of ModuleBuilder.



16
17
18
19
20
# File 'lib/gir_ffi/builders/module_builder.rb', line 16

def initialize(module_name, namespace: module_name, version: nil)
  @namespace = namespace
  @version = version
  @safe_namespace = module_name
end

Instance Method Details

#build_namespaced_class(classname) ⇒ Object



40
41
42
43
# File 'lib/gir_ffi/builders/module_builder.rb', line 40

def build_namespaced_class(classname)
  info = find_namespaced_class_info(classname)
  Builder.build_class info
end

#find_namespaced_class_info(classname) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/gir_ffi/builders/module_builder.rb', line 45

def find_namespaced_class_info(classname)
  name = classname.to_s
  info = gir.find_by_name(@namespace, name) ||
    gir.find_by_name(@namespace, name.sub(/^./, &:downcase))
  unless info
    raise NameError,
          "Class #{classname} not found in namespace #{@namespace}"
  end
  info
end

#generateObject



22
23
24
# File 'lib/gir_ffi/builders/module_builder.rb', line 22

def generate
  modul
end

#method_available?(method) ⇒ Boolean

Returns:



36
37
38
# File 'lib/gir_ffi/builders/module_builder.rb', line 36

def method_available?(method)
  function_introspection_data(method.to_s) and true
end

#setup_method(method) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/gir_ffi/builders/module_builder.rb', line 26

def setup_method(method)
  go = function_introspection_data method.to_s
  return false unless go

  Builder.attach_ffi_function lib, go
  modul.class_eval FunctionBuilder.new(go).method_definition, __FILE__, __LINE__

  true
end