Class: GirFFI::Builder::Module

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

Overview

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

Instance Method Summary collapse

Methods included from GirFFI::BuilderHelper

#const_defined_for, #optionally_define_constant

Constructor Details

#initialize(namespace, version = nil) ⇒ Module

Returns a new instance of Module.



12
13
14
15
16
17
# File 'lib/gir_ffi/builder/module.rb', line 12

def initialize namespace, version=nil
  @namespace = namespace
  @version = version
  # FIXME: Pass safe namespace as an argument
  @safe_namespace = @namespace.gsub(/^(.)/) { $1.upcase }
end

Instance Method Details

#build_moduleObject



46
47
48
49
50
51
52
# File 'lib/gir_ffi/builder/module.rb', line 46

def build_module
  unless defined? @module
    build_dependencies
    build_module_non_recursive
  end
  @module
end

#build_module_non_recursiveObject



54
55
56
57
58
59
60
61
# File 'lib/gir_ffi/builder/module.rb', line 54

def build_module_non_recursive
  unless defined? @module
    instantiate_module
    setup_lib_for_ffi
    setup_module unless already_set_up
  end
  @module
end

#build_namespaced_class(classname) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/gir_ffi/builder/module.rb', line 37

def build_namespaced_class classname
  info = gir.find_by_name @namespace, classname.to_s
  if info.nil?
    raise NameError.new(
      "Class #{classname} not found in namespace #{@namespace}")
  end
  Builder.build_class info
end

#generateObject



19
20
21
# File 'lib/gir_ffi/builder/module.rb', line 19

def generate
  build_module
end

#pretty_printObject



63
64
65
66
67
68
69
70
# File 'lib/gir_ffi/builder/module.rb', line 63

def pretty_print
  buf = "module #{@safe_namespace}\n"
  gir.infos(@namespace).each do |info|
    buf << sub_builder(info).pretty_print.indent
    buf << "\n"
  end
  buf << "end"
end

#setup_method(method) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gir_ffi/builder/module.rb', line 23

def setup_method method
  go = function_introspection_data method.to_s

  return false if go.nil?

  modul = build_module
  lib = modul.const_get(:Lib)

  Builder.attach_ffi_function lib, go
  modul.class_eval function_definition(go, lib)

  true
end