class GirFFI::Builders::ConstructorBuilder

Implements the creation of a Ruby constructor definition out of a GIR IFunctionInfo. TODO: Derive from BaseMethodBuilder

Public Class Methods

new(info) click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 13
def initialize(info)
  @info = info
  return_value_builder = NullReturnValueBuilder.new
  arg_builders = ArgumentBuilderCollection.new(return_value_builder, [])
  @template = MethodTemplate.new(self, arg_builders)
end

Public Instance Methods

invocation() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 47
def invocation
  "obj.__send__ #{initializer_name.to_sym.inspect}, #{method_arguments.join(', ')}"
end
method_arguments() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 32
def method_arguments
  ["*args", "&block"]
end
method_definition() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 20
def method_definition
  @template.method_definition
end
method_name() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 28
def method_name
  @info.safe_name
end
preparation() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 36
def preparation
  if @info.safe_name == "new"
    ["obj = allocate"]
  else
    [
      "raise NoMethodError unless self == #{@info.container.full_name}",
      "obj = allocate"
    ]
  end
end
result() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 51
def result
  ["obj"]
end
singleton_method?() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 24
def singleton_method?
  true
end

Private Instance Methods

initializer_name() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 57
def initializer_name
  @info.safe_name.sub(/^new/, "initialize")
end