Class: GirFFI::Builders::ConstructorBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gir_ffi/builders/constructor_builder.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ ConstructorBuilder

Returns a new instance of ConstructorBuilder.



13
14
15
16
17
18
# 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

Instance Method Details

#invocationObject



47
48
49
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 47

def invocation
  "obj.__send__ #{initializer_name.to_sym.inspect}, #{method_arguments.join(", ")}"
end

#method_argumentsObject



32
33
34
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 32

def method_arguments
  ["*args", "&block"]
end

#method_definitionObject



20
21
22
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 20

def method_definition
  @template.method_definition
end

#method_nameObject



28
29
30
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 28

def method_name
  @info.safe_name
end

#preparationObject



36
37
38
39
40
41
42
43
44
45
# 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

#resultObject



51
52
53
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 51

def result
  ["obj"]
end

#singleton_method?Boolean

Returns:



24
25
26
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 24

def singleton_method?
  true
end