Class: RubyBindgen::Generators::Generator
- Inherits:
-
Object
- Object
- RubyBindgen::Generators::Generator
- Defined in:
- lib/ruby-bindgen/generators/generator.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#inputter ⇒ Object
readonly
Returns the value of attribute inputter.
-
#outputter ⇒ Object
readonly
Returns the value of attribute outputter.
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(inputter, outputter, config) ⇒ Generator
constructor
A new instance of Generator.
- #project ⇒ Object
- #render_template(template, local_variables = {}) ⇒ Object
-
#translation_unit_file?(cursor) ⇒ Boolean
Check whether a cursor originates from the translation unit’s main file.
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/ruby-bindgen/generators/generator.rb', line 6 def config @config end |
#inputter ⇒ Object (readonly)
Returns the value of attribute inputter.
6 7 8 |
# File 'lib/ruby-bindgen/generators/generator.rb', line 6 def inputter @inputter end |
#outputter ⇒ Object (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_dir ⇒ Object
47 48 49 |
# File 'lib/ruby-bindgen/generators/generator.rb', line 47 def self.template_dir raise NotImplementedError end |
Instance Method Details
#generate ⇒ Object
19 20 21 |
# File 'lib/ruby-bindgen/generators/generator.rb', line 19 def generate raise NotImplementedError end |
#project ⇒ Object
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.
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 |