class GirFFI::Builder::Module

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

Public Class Methods

new(namespace, version=nil) click to toggle source
# 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(%r^(.)/) { $1.upcase }
end

Public Instance Methods

build_module() click to toggle source
# 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_recursive() click to toggle source
# 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) click to toggle source
# 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
generate() click to toggle source
# File lib/gir_ffi/builder/module.rb, line 19
def generate
  build_module
end
pretty_print() click to toggle source
# 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) click to toggle source
# 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