Class: CTypes::Exporter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ctypes/exporter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Used to export CTypes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output = "".dup) ⇒ Exporter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Exporter.



10
11
12
13
14
15
# File 'lib/ctypes/exporter.rb', line 10

def initialize(output = "".dup)
  @output = output
  @indent = 0
  @indented = false
  @type_lookup = nil
end

Instance Attribute Details

#outputObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
# File 'lib/ctypes/exporter.rb', line 17

def output
  @output
end

#type_lookup=(value) ⇒ Object (writeonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
# File 'lib/ctypes/exporter.rb', line 16

def type_lookup=(value)
  @type_lookup = value
end

Instance Method Details

#<<(arg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ctypes/exporter.rb', line 30

def <<(arg)
  case arg
  when CTypes::Type
    if buf = @type_lookup&.call(arg)
      self << buf
    else
      nest(2) { arg.export_type(self) }
    end
  when ::String
    unless @indented
      @output << " " * @indent
      @indented = true
    end
    @output << arg
    @indented = !arg.end_with?("\n")
  else
    raise Error, "not supported"
  end
end

#breakObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/ctypes/exporter.rb', line 26

def break
  self << "\n"
end

#nest(indent, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
22
23
24
# File 'lib/ctypes/exporter.rb', line 19

def nest(indent, &block)
  @indent += indent
  yield
ensure
  @indent -= indent
end