class GirFFI::Builders::ConstructorBuilder

Implements the creation of a Ruby constructor definition out of a GIR IFunctionInfo.

Public Class Methods

new(info) click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 10
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 44
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 29
def method_arguments
  ['*args']
end
method_definition() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 17
def method_definition
  @template.method_definition
end
method_name() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 25
def method_name
  @info.safe_name
end
preparation() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 33
def preparation
  if @info.safe_name == 'new'
    ['obj = allocate']
  else
    [
      "raise NoMethodError unless self == #{@info.container.full_type_name}",
      'obj = allocate'
    ]
  end
end
result() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 48
def result
  ['obj']
end
singleton_method?() click to toggle source
# File lib/gir_ffi/builders/constructor_builder.rb, line 21
def singleton_method?
  true
end

Private Instance Methods

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