Class: RubyBindgen::Generators::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-bindgen/generators/generator.rb

Direct Known Subclasses

CMake, FFI, Rice

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inputter, outputter, config) ⇒ Generator

Returns a new instance of Generator.



8
9
10
11
12
13
# File 'lib/ruby-bindgen/generators/generator.rb', line 8

def initialize(inputter, outputter, config)
  @inputter = inputter
  @outputter = outputter
  @config = config
  @project = config[:project]&.gsub(/-/, '_')
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/ruby-bindgen/generators/generator.rb', line 6

def config
  @config
end

#inputterObject (readonly)

Returns the value of attribute inputter.



6
7
8
# File 'lib/ruby-bindgen/generators/generator.rb', line 6

def inputter
  @inputter
end

#outputterObject (readonly)

Returns the value of attribute outputter.



6
7
8
# File 'lib/ruby-bindgen/generators/generator.rb', line 6

def outputter
  @outputter
end

Class Method Details

.template_dirObject

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/ruby-bindgen/generators/generator.rb', line 47

def self.template_dir
  raise NotImplementedError
end

Instance Method Details

#generateObject

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/ruby-bindgen/generators/generator.rb', line 19

def generate
  raise NotImplementedError
end

#projectObject



15
16
17
# File 'lib/ruby-bindgen/generators/generator.rb', line 15

def project
  @project
end

#render_template(template, local_variables = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby-bindgen/generators/generator.rb', line 23

def render_template(template, local_variables = {})
  template_path = File.join(self.class.template_dir, "#{template}.erb")
  template_content = File.read(template_path)
  template = ERB.new(template_content, :trim_mode => '-')
  template.filename = template_path # This allows debase to stop at breakpoints in templates!
  b = self.binding
  local_variables.each do |key, value|
    b.local_variable_set(key, value)
  end
  template.result(b)
end

#translation_unit_file?(cursor) ⇒ Boolean

Check whether a cursor originates from the translation unit’s main file. This intentionally uses libclang file-object equality rather than comparing raw file-name strings. Cursor locations only expose the file path string, so we resolve that path back through ‘translation_unit.file(…)` and let libclang compare the resulting file objects.

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/ruby-bindgen/generators/generator.rb', line 40

def translation_unit_file?(cursor)
  file_name = cursor.file_location.file
  translation_unit_file = cursor.translation_unit.file
  file = file_name && cursor.translation_unit.file(file_name)
  file && translation_unit_file && file == translation_unit_file
end