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.

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ ConstructorBuilder

Returns a new instance of ConstructorBuilder.



10
11
12
13
14
15
# 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

Instance Method Details

#invocationObject



44
45
46
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 44

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

#method_argumentsObject



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

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

#method_definitionObject



17
18
19
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 17

def method_definition
  @template.method_definition
end

#method_nameObject



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

def method_name
  @info.safe_name
end

#preparationObject



33
34
35
36
37
38
39
40
41
42
# 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

#resultObject



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

def result
  ['obj']
end

#singleton_method?Boolean

Returns:

  • (Boolean)


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

def singleton_method?
  true
end